现在,NUnit 是否为每个包含的测试方法创建测试夹具类的新实例?

发布于 2024-11-27 12:43:31 字数 231 浏览 1 评论 0原文

正如一本相当老的书所写的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半夏半凉 2024-12-04 12:43:31

为该装置中的所有测试创建一次装置。

对于给定的固定装置类,固定装置中的所有测试都会运行一次 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.)

ぶ宁プ宁ぶ 2024-12-04 12:43:31

从 3.13 开始,您可以使用 https://docs.nunit 进行配置

LifeCycle.SingleInstance    A single instance is created and shared for all test cases
LifeCycle.InstancePerTestCase   A new instance is created for each test case

。 org/articles/nunit/writing-tests/attributes/fixturelifecycle.html

Since 3.13 you can configure that with

LifeCycle.SingleInstance    A single instance is created and shared for all test cases
LifeCycle.InstancePerTestCase   A new instance is created for each test case

https://docs.nunit.org/articles/nunit/writing-tests/attributes/fixturelifecycle.html

我ぃ本無心為│何有愛 2024-12-04 12:43:31

我发现这是一个影响我的问题,并且还发现此链接提供了该问题的一些历史记录;
https://blogs.msdn.microsoft.com/jamesnewkirk/2004/12/04/why-variables-in-nunit-testfixture-classes-should-be-static

我认为我们编写 NUnit V2.0 时犯下的最大错误之一是没有为每个包含的测试方法创建测试夹具类的新实例。

尚未在 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

I think one of the biggest screw-ups that was made when we wrote NUnit V2.0 was to not create a new instance of the test fixture class for each contained test method.

Not yet tested this in V3 to see if its changed

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文