Loading...
Loading...
Compare original and translation side by side
| Framework | Test class markers | Test method markers |
|---|---|---|
| MSTest | | |
| xUnit | (none — convention-based) | |
| NUnit | | |
| TUnit | | |
| 框架 | 测试类标记 | 测试方法标记 |
|---|---|---|
| MSTest | | |
| xUnit | (无,基于约定识别) | |
| NUnit | | |
| TUnit | | |
| Category | MSTest | xUnit | NUnit |
|---|---|---|---|
| Equality | | | |
| Boolean | | | |
| Null | | | |
| Exception | | | |
| Collection | | | |
| String | | | |
| Type | | | |
| Inconclusive | | skip via | |
| Fail | | | |
Should*.Should()Verify()| 分类 | MSTest | xUnit | NUnit |
|---|---|---|---|
| 相等判断 | | | |
| 布尔判断 | | | |
| 空值判断 | | | |
| 异常判断 | | | |
| 集合判断 | | | |
| 字符串判断 | | | |
| 类型判断 | | | |
| 不确定结果 | | 通过 | |
| 强制失败 | | | |
Should*.Should()Verify()| Pattern | Example |
|---|---|
| Thread sleep | |
| Task delay | |
| SpinWait | |
| 模式 | 示例 |
|---|---|
| 线程睡眠 | |
| 任务延迟 | |
| 自旋等待 | |
| Framework | Annotation | With reason |
|---|---|---|
| MSTest | | |
| xUnit | | (reason is required) |
| NUnit | | (reason is required) |
| TUnit | | (reason is required) |
| Conditional | | (no reason possible) |
| 框架 | 注解 | 支持填写原因 |
|---|---|---|
| MSTest | | |
| xUnit | | (必须填写原因) |
| NUnit | | (必须填写原因) |
| TUnit | | (必须填写原因) |
| 条件编译 | | (无法填写原因) |
trycatch// Instead of try/catch (matches exact type):
var ex = Assert.ThrowsExactly<InvalidOperationException>(
() => processor.ProcessOrder(emptyOrder));
Assert.AreEqual("Order must contain at least one item", ex.Message);
// Or (also matches derived types):
var ex = Assert.Throws<InvalidOperationException>(
() => processor.ProcessOrder(emptyOrder));
Assert.AreEqual("Order must contain at least one item", ex.Message);var ex = Assert.Throws<InvalidOperationException>(
() => processor.ProcessOrder(emptyOrder));
Assert.Equal("Order must contain at least one item", ex.Message);var ex = Assert.Throws<InvalidOperationException>(
() => processor.ProcessOrder(emptyOrder));
Assert.That(ex.Message, Is.EqualTo("Order must contain at least one item"));trycatch// 替代try/catch(匹配 exact 类型):
var ex = Assert.ThrowsExactly<InvalidOperationException>(
() => processor.ProcessOrder(emptyOrder));
Assert.AreEqual("Order must contain at least one item", ex.Message);
// 或者(也匹配派生类型):
var ex = Assert.Throws<InvalidOperationException>(
() => processor.ProcessOrder(emptyOrder));
Assert.AreEqual("Order must contain at least one item", ex.Message);var ex = Assert.Throws<InvalidOperationException>(
() => processor.ProcessOrder(emptyOrder));
Assert.Equal("Order must contain at least one item", ex.Message);var ex = Assert.Throws<InvalidOperationException>(
() => processor.ProcessOrder(emptyOrder));
Assert.That(ex.Message, Is.EqualTo("Order must contain at least one item"));| Smell indicator | What to look for |
|---|---|
| File system | |
| Database | |
| Network | |
| Environment | |
| Acceptable | |
| 坏味道指标 | 排查点 |
|---|---|
| 文件系统 | 带硬编码路径的 |
| 数据库 | |
| 网络请求 | 未重写 |
| 环境变量 | |
| 可接受用法 | |
IntegrationE2EEndToEndAcceptance[TestCategory("Integration")][Trait("Category", "Integration")][Category("Integration")].IntegrationTests.E2ETestsIntegrationE2EEndToEndAcceptance[TestCategory("Integration")][Trait("Category", "Integration")][Category("Integration")].IntegrationTests.E2ETests| Framework | Setup | Teardown |
|---|---|---|
| MSTest | | |
| xUnit | constructor | |
| NUnit | | |
| MSTest (class) | | |
| NUnit (class) | | |
| xUnit (class) | | fixture's |
| 框架 | Setup | Teardown |
|---|---|---|
| MSTest | | |
| xUnit | 构造函数 | |
| NUnit | | |
| MSTest(类级别) | | |
| NUnit(类级别) | | |
| xUnit(类级别) | | fixture 的 |