本文介绍了现在,NUnit 是否为每个包含的测试方法创建了测试装置类的新实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如一本相当老的书所写的XUnit Patterns NUnit 2.0 没有创建新的测试装置对于每个测试,并且因此,如果测试正在操纵夹具的某些状态,它就会被共享并可能导致各种不良副作用.

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.

这还是一样吗?我在官网上找过,没找到,好久没用NUnit了.

Is this still the same? I tried to find it on official site but failed, and havent used NUnit for a while.

推荐答案

从 3.13 开始,您可以使用

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

这篇关于现在,NUnit 是否为每个包含的测试方法创建了测试装置类的新实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 04:11