现在,NUnit 是否为每个包含的测试方法创建测试夹具类的新实例?
正如一本相当老的书所写的XUnit 模式 NUnit 2.0 没有为每个测试创建新的测试装置,因此,如果测试正在操纵夹具的某些状态,它就会被共享,并可能导致各种不良的副作用。
这还是一样吗?我试图在官方网站上找到它,但失败了,并且已经有一段时间没有使用 NUnit 了。
As written in a fairly old book XUnit Patterns NUnit 2.0 did not create new test fixtures for each test, and because of that if tests were manipulating some state of fixture it became shared and could cause various bad side effects.
Is this still the same? I tried to find it on official site but failed, and havent used NUnit for a while.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为该装置中的所有测试创建一次装置。
对于给定的固定装置类,固定装置中的所有测试都会运行一次 FixtureSetup 方法,并且每个测试都会运行一次设置方法。因此,任何需要重置的状态都应该在 Setup 方法(或 TearDown,在每个测试结束时运行)中完成。
The fixture is created once for all of the tests in that fixture.
For a given fixture class, a FixtureSetup method is run once for all of the tests in a fixture, and a Setup method is run once for each test. So, any state that needs to be reset should be done in a Setup method (or TearDown, which is run at the end of each test.)
从 3.13 开始,您可以使用 https://docs.nunit 进行配置
。 org/articles/nunit/writing-tests/attributes/fixturelifecycle.html
Since 3.13 you can configure that with
https://docs.nunit.org/articles/nunit/writing-tests/attributes/fixturelifecycle.html
我发现这是一个影响我的问题,并且还发现此链接提供了该问题的一些历史记录;
https://blogs.msdn.microsoft.com/jamesnewkirk/2004/12/04/why-variables-in-nunit-testfixture-classes-should-be-static
尚未在 V3 中对此进行测试以查看其是否已更改
I found that this was an issue that affected me and also found this link which provides a bit of history to the issue;
https://blogs.msdn.microsoft.com/jamesnewkirk/2004/12/04/why-variables-in-nunit-testfixture-classes-should-be-static
Not yet tested this in V3 to see if its changed