简体   繁体   English

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

[英]In xUnit.net, is it possible to run tests in order?

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

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: https://xunit.net/#releases查看我们最新版本中的示例: https : //xunit.net/#releases

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.如果您确实存在无法分离的自然依赖性,我建议您将测试合并为一个具有多个断言的单元。

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.例如,在 mbUnit 中,您可以将Order属性附加到您的测试属性。 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.许多 TDD 纯粹主义者认为这是一种滥用,任何需要顺序的测试都应该合并到一个单独的单元测试中,但许多人发现能够在某些情况下对测试进行排序很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM