NUnit 测试运行顺序

NUnit Test Run Order(NUnit 测试运行顺序)
本文介绍了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")]

如果您有依赖于特定环境条件的测试,请考虑 TestFixtureSetUpTestFixtureTearDown 属性,它们允许您标记要在测试之前和之后执行的方法.

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 测试运行顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
quot;Overflowquot; compiler error with -9223372036854775808L(编译器错误-9223372036854775808L(Q;溢出Q))
Visual Studio 2010 ReportViewer Assembly References(Visual Studio 2010 ReportViewer程序集引用)
Weird behaviour when I open a reportviewer in WPF(在WPF中打开报表查看器时出现奇怪的行为)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)