作为较大命名空间的一部分运行时,nUnit 测试失败
我遇到了一个有趣的情况。在我的测试程序集中,我有包含特定测试类的文件夹,即 TestFixture。例如,考虑 VS 中的以下层次结构:
Sol TestProject TestFolder1 TestClass1 TestClass2 TestFolder2 TestClass3
现在,当我在命令行运行以下命令时:
nunit-console.exe /run:Sol.TestProject.TestFolder1.TestClass2 TestProject.dll
一切运行良好,所有测试都通过。但是,如果我按如下方式运行:
nunit-console.exe /run:Sol.TestProject.TestFolder1 TestProject.dll
在这种情况下,TestClass2 中的某些测试会失败。
我尝试转储测试中涉及的一些相关对象的状态,并且在这两种情况下,在测试代码开始时状态似乎都很好。另外,TestClass1/2/3 没有超类做某事——所以这也被排除了。你知道这里还会发生什么吗?
我正在使用 VS2010/.NET4.0 (4.0.30319.1)/nUnit 2.5.9。
I am having an interesting situation. In my test assembly, I have folders having specific test classes, i.e., TestFixture's. Consider, for e.g., the following hierarchy in VS:
Sol TestProject TestFolder1 TestClass1 TestClass2 TestFolder2 TestClass3
Now, when I run the following at command line:
nunit-console.exe /run:Sol.TestProject.TestFolder1.TestClass2 TestProject.dll
Things are running fine and all the tests are passing. But, if I run as below:
nunit-console.exe /run:Sol.TestProject.TestFolder1 TestProject.dll
In this case, some of the tests in TestClass2 are failing.
I have tried dumping the state of some of the relevant objects involved in the test, and the state seemed fine at the beginning of the test code in both cases. Also, TestClass1/2/3 do not have a superclass doing something - so that is ruled out as well. Any ideas what else can be happening here?
I am using VS2010/.NET4.0 (4.0.30319.1)/nUnit 2.5.9.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
终于明白了这一点。我使用 单例类 来存储某些选项。看起来单例类实例在不同 TestFixtures(即测试类)的运行之间保留,当它们一起运行时,例如,对于文件夹或项目。我最初没有转储该对象的状态,因为我认为单例类将为每个 TestFixtures 提供新实例。有趣的发现,希望这对某人有帮助。
Finally figured this out. I was using a singleton class for storing certain options. Looks like the singleton class instance is retained between runs of different TestFixtures (i.e., test classes), when they are run together, e.g., for a folder or for a project. I did not dump the state of this object initially, because I thought that the singleton class will be having new instance for each of the TestFixtures. Interesting finding, hope this helps someone.