80 lines
1.8 KiB
Markdown
80 lines
1.8 KiB
Markdown
# 测试方法
|
||
|
||
## 测试框架
|
||
MSTest
|
||
|
||
### 测试命令
|
||
|
||
1. 测试全部用例
|
||
```bash
|
||
dotnet test
|
||
```
|
||
|
||
2. 测试指定用例
|
||
```bash
|
||
dotnet test --filter "FullyQualifiedName=ThreatSource.Tests.Utils.Vector3DPerformanceTests.Baseline_Vector3D_Class_Performance"
|
||
```
|
||
|
||
3. 测试指定用例并输出详细日志
|
||
```bash
|
||
dotnet test --filter "FullyQualifiedName=ThreatSource.Tests.Utils.Vector3DPerformanceTests.Baseline_Vector3D_Class_Performance" --logger "console;verbosity=detailed" | cat
|
||
```
|
||
|
||
4. 测试是否编译正常
|
||
```bash
|
||
dotnet build
|
||
```
|
||
|
||
5. 日常开发测试(排除性能测试):
|
||
```bash
|
||
dotnet test --filter "Category!=Performance"
|
||
```
|
||
|
||
6. 仅运行性能测试:
|
||
```bash
|
||
dotnet test --filter "Category=Performance" --logger "console;verbosity=detailed"
|
||
```
|
||
|
||
7. 按类名排除:
|
||
```bash
|
||
dotnet test --filter "FullyQualifiedName!~PerformanceTest"
|
||
```
|
||
|
||
8. 组合过滤器(更严格):
|
||
```bash
|
||
dotnet test --filter "Category!=Performance&FullyQualifiedName!~Performance"
|
||
```
|
||
|
||
9. 运行 Release 模式下的性能测试:
|
||
```bash
|
||
dotnet test --configuration Release --filter "RunPerformanceTest" --verbosity minimal --nologo --logger "console;verbosity=normal"
|
||
```
|
||
|
||
### 测试报告
|
||
时间:2025-05-16
|
||
测试目的:测试 Vector3D 作为类和结构体的性能差异
|
||
测试用例:ThreatSource.Tests.Utils.Vector3DPerformanceTests.Baseline_Vector3D_Class_Performance
|
||
|
||
测试结果:
|
||
|
||
1. 这是更改为 struct 之前的性能(作为类的 Vector3D):
|
||
Creation: 67 ms
|
||
Addition: 29 ms
|
||
Subtraction: 19 ms
|
||
Scalar Mult: 16 ms
|
||
Dot Product: 11 ms
|
||
Cross Product: 24 ms
|
||
Magnitude: 12 ms
|
||
Normalization: 40 ms
|
||
|
||
2. 这是更改为 struct 之后 的性能:
|
||
Creation: 21 ms
|
||
Addition: 23 ms
|
||
Subtraction: 22 ms
|
||
Scalar Mult: 15 ms
|
||
Dot Product: 12 ms
|
||
Cross Product: 25 ms
|
||
Magnitude: 14 ms
|
||
Normalization: 51 ms
|
||
|