NUnit Test Run Order(NUnit 测试运行顺序)
问题描述
默认情况下,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 测试运行顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:NUnit 测试运行顺序
基础教程推荐
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- WPF 模态进度窗口 2022-01-01
