C# 命名空间是分层的吗?
背景: 我正在开发一个测试框架,并且我有每个命名空间的设置装置。例如命名空间 A 中的一个 SetUpFixture 和命名空间 A.B 中的一个。
实际问题: 如果我调用 TestRunner.RunAllTestsInNamespace("A.B") - 测试运行器应该只调用 namespace A.B 中的 SetUpFixture 还是 namespace A 中的 SetUpFixture?
(或者相反:如果我调用 TestRunner.RunAllTestsInNamespace("A") - 测试运行器是否也应该执行命名空间 A.B 中的所有测试?
请您参考如下方法:
关于您的问题:
If I call TestRunner.RunAllTestsInNamespace("A.B") - should the test runner only call the SetUpFixture in namespace A.B or also the one in namespace A?
假设你有结构:
A.Setup1
A.Test1
A.B.Setup2
A.B.Test2
如果您在现有框架(例如 NUnit)中进行一些简单测试,您会发现遵循的行为似乎是:
- 运行
A.Test1执行A.Setup1和A.Test1 - 运行
A.B.Test2执行A.Setup1、A.B.Setup2、A.B.Test2
这是 NUnit 的行为。其他人的行为可能有所不同。
您可能想要全面调查和了解现有测试框架(NUnit、XUnit.Net、MSTest 等)的行为。
