如何串行运行 NUnit 测试装置?
我有几套在 C#/NUNit 中实现的集成测试。每个测试套件都是一个单独的类,每个夹具设置都会从脚本创建并填充 SQL Server 数据库。在 Resharper 5.1 之前,这一切都运行得很好。
不幸的是,Resharper 5.1 开始同时运行多个装置。这是一个重大变化 - 他们都试图创建和填充相同的数据库,这显然最终会陷入混乱。有什么方法可以让 Resharper 连续运行我的测试装置吗?
如果没有,您建议如何连续运行我的 NUnit 测试装置,一次运行一个装置? 各个测试的运行顺序并不重要。
I have several suites of integration tests implemented in C#/NUNit. Each test suite is a separate class, each fixture setup creates and populates a SQL Server database from scripts. This all used to work just fine prior to Resharper 5.1.
Unfortunately, Resharper 5.1 begins to run several fixtures at the same time. This is a breaking change - they are all attempting to create and populate the same database, which obviously ends up in an mess. Is there any way I could have Resharper run my test fixtures serially?
If not, what would you suggest to run my NUnit test fixtures serially, one fixture at a time?
The order in which individual tests run does not matter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不知道是否可以阻止ReSharper并行运行测试;如果没有,以下 hack 可能会起作用:创建一个带有静态只读
Monitor
成员的静态类。然后,在[TestFixtureSetUp]
中,在监视器上调用Enter()
,并在[TestFixtureTearDown]中调用监视器上的
。这样,一次只允许运行一个测试装置。不过不漂亮...Exit()
]I don't know whether it is possible to prevent ReSharper from running tests in parallel; if not, the following hack might work: Create a static class with a static readonly
Monitor
member. Then, in[TestFixtureSetUp]
, callEnter()
on the monitor, and callExit()
on the monitor in[TestFixtureTearDown]
. That way, only one test fixture will be allowed to run at a time. Not pretty, though...你确定吗?我刚刚尝试过这一点.. 通过在 3 个 diff NUnit 固定装置中的测试中放置以下形式的跟踪,然后是“全部运行”。似乎没有并行运行。
我看到的输出是:(R# Build 5.1.1753.1)
Are you sure about this ? I just tried this out.. by putting a trace of the following form in tests in 3 diff NUnit fixtures followed by a "Run all". Doesn't seem to be running in parallel.
Output I see is : (R# Build 5.1.1753.1)
除非被测试的代码有自己的事务管理,否则您可以在事务内运行每个测试。这样,不同的测试就不会互相干扰。此外,您不必担心每次测试后的清理工作,因为每个测试的事务可以在测试完成后简单地中止。
在我们的项目中,我们通常让集成测试派生自一个或多或少像这样的类:
Unless the code being tested does its own transaction management, you can run each test inside a transaction. In that way, the different tests won't disturb each other. Also, you don't have to worry about cleaning up after each test, since the each test's transaction can simply abort after the test is completed.
In our projects, we usually let our integration tests derive from a class that looks more or less like this:
给它们按字母顺序命名,即在它们前面加上一个表示它们运行顺序的字母。如果您需要这种情况发生,您也应该能够接受这种令人讨厌的命名约定。
Give them alphabetical names, i.e. prefix them with a letter that signifies their running order. If you need this to happen you should be able to accept this nasty naming convention too.