在xUnit.net中,是否可以按顺序运行测试?

时间:2022-10-15 22:57:16

I know you generally should not depend on order for your unit tests, but in xunit is it possible to make your tests run in a certain order?

我知道你通常不应该依赖于你的单元测试的顺序,但是在xunit中是否可以让你的测试以一定的顺序运行?

3 个解决方案

#1


16  

There is a sample in our Samples project named PrioritizedFixtureSample which allows you to control the ordering of tests.

我们的Samples项目中有一个名为PrioritizedFixtureSample的示例,它允许您控制测试的顺序。

See the samples in our latest release: http://xunit.codeplex.com/Release/ProjectReleases.aspx

请参阅我们最新版本中的示例:http://xunit.codeplex.com/Release/ProjectReleases.aspx

#2


5  

No, I don't believe so, but then unit tests by definition should be independent so order shouldn't matter. Where you do have a natural dependency you can't separate I'd suggest you combine the tests into one unit with multiple asserts.

不,我不相信,但是根据定义,单元测试应该是独立的,所以顺序无关紧要。你确实有自然依赖的地方你不能分开我建议你把测试合并到一个单元和多个断言中。

#3


2  

xUnit.net does not provide a way to order tests.

xUnit.net不提供订购测试的方法。

Some other frameworks do, however. For example, in mbUnit, you can attach an Order property to your test attributes. Many TDD purists feel that this is abusive, and any test that requires an order should be merged into a separate unit test, but many people find it useful to be able to order tests in certain circumstances.

但是,其他一些框架也是如此。例如,在mbUnit中,您可以将Order属性附加到测试属性。许多TDD纯粹主义者认为这是滥用,任何需要订单的测试都应该合并到一个单独的单元测试中,但是很多人发现在某些情况下能够订购测试很有用。

#1


16  

There is a sample in our Samples project named PrioritizedFixtureSample which allows you to control the ordering of tests.

我们的Samples项目中有一个名为PrioritizedFixtureSample的示例,它允许您控制测试的顺序。

See the samples in our latest release: http://xunit.codeplex.com/Release/ProjectReleases.aspx

请参阅我们最新版本中的示例:http://xunit.codeplex.com/Release/ProjectReleases.aspx

#2


5  

No, I don't believe so, but then unit tests by definition should be independent so order shouldn't matter. Where you do have a natural dependency you can't separate I'd suggest you combine the tests into one unit with multiple asserts.

不,我不相信,但是根据定义,单元测试应该是独立的,所以顺序无关紧要。你确实有自然依赖的地方你不能分开我建议你把测试合并到一个单元和多个断言中。

#3


2  

xUnit.net does not provide a way to order tests.

xUnit.net不提供订购测试的方法。

Some other frameworks do, however. For example, in mbUnit, you can attach an Order property to your test attributes. Many TDD purists feel that this is abusive, and any test that requires an order should be merged into a separate unit test, but many people find it useful to be able to order tests in certain circumstances.

但是,其他一些框架也是如此。例如,在mbUnit中,您可以将Order属性附加到测试属性。许多TDD纯粹主义者认为这是滥用,任何需要订单的测试都应该合并到一个单独的单元测试中,但是很多人发现在某些情况下能够订购测试很有用。