默认情况下,nunit 测试按字母顺序运行.有谁知道设置执行顺序的任何方法?是否存在此属性?
By default nunit tests run alphabetically. Does anyone know of any way to set the execution order? Does an attribute exist for this?
每个单元测试都应该能够独立运行和独立运行.如果它们满足此标准,则顺序无关紧要.
Your unit tests should each be able to run independently and stand alone. If they satisfy this criterion then the order does not matter.
但在某些情况下,您需要先运行某些测试.一个典型的例子是在持续集成的情况下,一些测试比其他的运行时间更长.我们使用类别属性,以便我们可以在使用数据库的测试之前运行使用模拟的测试.
There are occasions however where you will want to run certain tests first. A typical example is in a Continuous Integration situation where some tests are longer running than others. We use the category attribute so that we can run the tests which use mocking ahead of the tests which use the database.
即把它放在你快速测试的开始
i.e. put this at the start of your quick tests
[Category("QuickTests")]
如果您有依赖于特定环境条件的测试,请考虑 TestFixtureSetUp 和 TestFixtureTearDown 属性,它们允许您标记要在测试之前和之后执行的方法.
Where you have tests which are dependant on certain environmental conditions, consider the TestFixtureSetUp and TestFixtureTearDown attributes, which allow you to mark methods to be executed before and after your tests.
这篇关于NUnit 测试运行顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!