NUnit-Console 命令行选项详解
本文为 Dennis Gao 原创或翻译技术文章,发表于博客园博客,未经作者本人允许禁止任何形式的转载。
NUnit-Console 命令行选项
NUnit-Console 命令行选项列表
Options | Description |
/fixture=STR |
Test fixture or namespace to be loaded (Deprecated) (Short format: /load=STR) |
/run=STR |
Name of the test case(s), fixture(s) or namespace(s) to run |
/runlist=STR |
Name of a file containing a list of the tests to run, one per line |
/config=STR |
Project configuration (e.g.: Debug) to load |
/result=STR |
Name of XML result file (Default: TestResult.xml) (Short format: /xml=STR) |
/xmlConsole |
Display XML to the console (Deprecated) |
/noresult |
Suppress XML result output (Short format: /noxml) |
/output=STR |
File to receive test output (Short format: /out=STR) |
/err=STR |
File to receive test error output |
/work=STR |
Work directory for output files |
/labels |
Label each test in stdOut |
/trace=X |
Set internal trace level: Off, Error, Warning, Info, Verbose |
/include=STR |
List of categories to include |
/exclude=STR |
List of categories to exclude |
/framework=STR |
Framework version to be used for tests |
/process=X |
Process model for tests: Single, Separate, Multiple |
/domain=X |
AppDomain Usage for tests: None, Single, Multiple |
/apartment=X |
Apartment for running tests: MTA (Default), STA |
/noshadow |
Disable shadow copy when running in separate domain |
/nothread |
Disable use of a separate thread for tests |
/basepath=STR |
Base path to be used when loading the assemblies |
/privatebinpath=STR |
Additional directories to be probed when loading assemblies, separated by semicolons |
/timeout=X |
Set timeout for each test case in milliseconds |
/wait |
Wait for input before closing console window |
/nologo |
Do not display the logo |
/nodots |
Do not display progress |
/stoponerror |
Stop after the first test failure or error |
/cleanup |
Erase any leftover cache files and exit |
/help |
Display help (Short format: /?) |
指定运行哪些测试用例
运行指定程序集中的所有测试用例
nunit-console 命令行需要指定一个或多个文件方可运行。控制台程序会创建一个 XML 格式的测试执行结果。缺省的测试结果文件名为 TestResult.xml,放置在工作目录中。
控制台程序必须指定一个程序集或者工程文件。
如果要运行 nunit.tests.dll 程序集中包含的测试用例,可使用下面的命令行:
nunit-console nunit.tests.dll
如果需要通过 Visual Studio 工程文件运行 nunit.tests.dll 中的的测试,可使用:
nunit-console nunit.tests.csproj
如果需要通过自定义的 NUnit 测试工程来运行同样的测试,可使用:
nunit-console nunit.tests.nunit
运行指定程序集中指定的测试用例
可以通过 /run 选项指定测试的全名称来运行程序集中的某个测试用例。
nunit-console /run:NUnit.Tests.AssertionTests nunit.tests.dll
被运行测试的名称可以是一个测试用例、测试 Fixture 或者名空间。
也可以通过使用逗号分隔来指定多个测试。例如:
nunit-console /run:NUnit.Tests.AssertionTests,NUnit.Tests.ConstraintTests nunit.tests.dll
/fixture 选项已经被声明为弃用,可以使用 /run 选项来代替。
通过单独的文件来指定运行测试列表
可以通过创建一个包含需要运行的测试列表的文件,使用 /runlist 选项来执行测试:
nunit-console /runlist:testlist.txt nunit.tests.dll
"testlist.txt" 文件中包含了每个测试的全名称,每行列举一个测试。被运行测试的名称可以是一个测试用例、测试 Fixture 或者名空间。
行首为 "#" 字符的为注释。
指定多个程序集
通过控制台命令行接口,可以在一次运行中指定运行多个程序集中的测试。例如:
nunit-console assembly1.dll assembly2.dll assembly3.dll
注:可以指定多个程序集文件,但是不支持多个 NUnit 或 Visual Studio 工程文件。
默认情况下,每个程序集中会在单独的 AppDomain 中执行。可以通过 /domain 选项来设置。
指定运行的 Configuration
可以通过 /config 选项控制测试运行的 Configuration。
nunit-console nunit.tests.csproj /config:Release
注:如果是直接加载程序集,则此选项无效。
通过测试类别 Category 来 Include 或 Exclude 测试
NUnit 通过 CategoryAttribute 属性来指定测试所属的类别。可以通过 /include 和 /exclude 选项来选择包含或排除指定的类别 Category。
下面的命令只运行 BaseLine 类别中的测试:
nunit-console myassembly.dll /include:BaseLine
下面的命令会运行除了 Database 类别外的所有测试:
nunit-console myassembly.dll /exclude:Database
从 NUnit 2.4.6 版本开始,可以在 /include 或 /exclude 中使用 Category 表达式。下面的表格中为一些示例:
NUnit Category Expression Examples
Expression | Action |
---|---|
A|B|C | Selects tests having any of the categories A, B or C. |
A,B,C | Selects tests having any of the categories A, B or C. |
A+B+C | Selects only tests having all three of the categories assigned |
A+B|C | Selects tests with both A and B OR with category C. |
A+B-C | Selects tests with both A and B but not C. |
-A | Selects tests not having category A assigned |
A+(B|C) | Selects tests having both category A and either of B or C |
A+B,C | Selects tests having both category A and either of B or C |
注:通过上面的例子可以看出,逗号和 "|" 拥有相同涵义,但逗号的优先级更高。
优先级顺序为:
- - 用于排除
- , 高优先级的或操作
- + 与操作
- | 低优先级的或操作
控制测试运行
指定 .NET Framework 版本
大多数应用程序都在某个特定版本的 CLR 下运行。少数的设计为可以在多版本下均可运行。不管哪种情况,为测试指定运行的 CLR 版本是非常重要的。
通过使用 /framework 选项可以指定运行时的版本。如果指定的版本与 NUnit 使用的版本不同,则测试将在一个独立的进程中被执行。
nunit-console myassembly.dll /framework:net-4.0
控制进程的使用
通过 /process 选项可以控制 NUnit 如何在进程中加载测试。
- Single :所有的测试运行在 nunit-console 进程中。默认选项。
- Separate :创建单独的进程中运行测试。
- Multiple :为每个程序集 Assembly 创建独立的进程运行测试。
控制 AppDomain 的使用
通过 /domain 选项可以控制运行测试所在的 AppDomain。
- None :不创建任何 AppDomain,所有测试运行在 Primary Domain 中。通常需要将 NUnit 程序集拷贝至工作目录。
- Single :创建新的 AppDomain 来运行测试。
- Multiple :为每个程序集 Assembly 创建独立的 AppDomain。
如果在命令行中列举了多个程序集,则默认选项为 Multiple。否则为 Single 选项。
控制 Apartment 的使用
通过 /apartment 选项可以指定运行测试线程的 ApartmentState (STA 或 MTA)。默认为 MTA。
指定超时时长
通过 /timeout 选项可以指定一个 int 值来设置运行测试的超时时长。如果任何测试超过了指定的超时时长,则该测试将被取消运行并同时报告一个错误信息。
也可以使用 TimeoutAttribute 属性来指定超时时长。
注:如果未使用该选项,则无超时限制。
控制测试的输出
重定向输出
通常在控制台显示的输出可以重定向到一个文件。
下面的命令将标准输入重定向到 TestResult.txt 文件:
nunit-console nunit.tests.dll /out:TestResult.txt
下面的命令将标准错误重定向到 StdErr.txt 文件:
nunit-console nunit.tests.dll /err:StdErr.txt
对测试输出进行标记
每个测试的输出会跟在前一个测试的输出之后。可以使用 /labels 选项创建一个标识,在每个测试输出的开始处显示。
指定 XML 结果文件名
控制台程序会创建一个 XML 形式的测试结果。可以使用 /result 将输出文件名改为 "console-test.xml":
nunit-console /result:console-test.xml nunit.tests.dll
可以使用 /noresult 选项禁止 XML 输出。
注:为了兼容早起版本,NUnit 2.6 版本仍然可识别 /xml 和 /noxml 选项。
指定输出的目录
默认情况下,所有的输出文件都被创建在当前工作目录。可以通过 /work 选项来指定具体的位置。
例如,下面的命令将会使 TestResult.xml 和 Output.txt 文件在 "results" 目录中被创建。
nunit-console /work:results /out:Output.txt nunit.tests.dll
参考资料
本文为 Dennis Gao 原创或翻译技术文章,发表于博客园博客,未经作者本人允许禁止任何形式的转载。
NUnit-Console 命令行选项详解的更多相关文章
- 详解Top命令 输出命令行选项及代码
Linux中的top命令显示系统上正在运行的进程.它是系统管理员最重要的工具之一.被广泛用于监视服务器的负载.在本篇中,我们会探索top命令的细节.top命令是一个交互命令.在运行top的时候还可以运 ...
- VLC命令行参数详解
VLC命令行参数详解 2012-11-29 14:00 6859人阅读 评论(0) 收藏 举报 Usage: vlc [options] [stream] ...You can specify mul ...
- 以太坊客户端Geth命令用法-参数详解
Geth在以太坊智能合约开发中最常用的工具(必备开发工具),一个多用途的命令行工具. 熟悉Geth可以让我们有更好的效率,大家可收藏起来作为Geth命令用法手册. 本文主要是对geth help的翻译 ...
- 命令行选项 - Mozilla 产品与私有技术 | MDN - Google Chrome
命令行选项 在本文章中 语法规则 使用命令行选项 示例 用户配置档 -CreateProfile profile_name -CreateProfile "profile_name prof ...
- telnet 命令使用方法详解,telnet命令怎么用
telnet 命令使用方法详解,telnet命令怎么用? 文章类型:电脑教程 原创:天诺时空 什么是Telnet? 对于Telnet的认识,不同的人持有不同的观点,可以把Telnet当成一种通信协 ...
- linux route命令的使用详解 添加永久静态路由 tracert traceroute
linux route命令的使用详解 添加永久静态路由 tracert traceroute route -n Linuxroute print Windows traceroute ...
- 【转载】Linux字符集和系统语言设置-LANG,locale,LC_ALL,POSIX等命令及参数详解
Linux字符集和系统语言设置-LANG,locale,LC_ALL,POSIX等命令及参数详解 1清风揽月10人评论5006人阅读2017-06-21 15:48:43 博文说明[前言]: 本文 ...
- linux-linux top 命令各参数详解
简介 top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器. top显示系统当前的进程和其他状况,是一个动态显示过程,即可以通过用户按 ...
- ping命令执行过程详解
[TOC] ping命令执行过程详解 机器A ping 机器B 同一网段 ping通知系统建立一个固定格式的ICMP请求数据包 ICMP协议打包这个数据包和机器B的IP地址转交给IP协议层(一组后台运 ...
随机推荐
- windows下apache+php+mysql 环境配置方法
一 准备 1 下载apache http://httpd.apache.org/download.cgi#apache24 httpd-2.2.22-win32-x86-openssl-0.9.8t. ...
- ZOJ3778--一道水题
Description As we all know, Coach Gao is a talented chef, because he is able to cook M dishes in the ...
- WSGI
[WSGI] WSGI:Web Server Gateway Interface. WSGI接口定义非常简单,它只要求Web开发者实现一个函数,就可以响应HTTP请求.我们来看一个最简单的Web版本的 ...
- delphi之多线程编程
本文的内容取自网络,并重新加以整理,在此留存仅仅是方便自己学习和查阅.所有代码均亲自测试 delphi7下测试有效.图片均为自己制作. 多线程应该是编程工作者的基础技能, 但这个基础我从来没学过,所以 ...
- Great StackOverflow questions
1. diffenece between MVC and MVP http://stackoverflow.com/questions/2056/what-are-mvp-and-mvc-and-wh ...
- 校验日期函数的js
/判断输入内容是否为空 function IsNull(){ var str = document.getElementById('str').value.trim(); if(str.length= ...
- .net 更新数据 ado.net parameter
UPDATE yborder_ordernotes SET recoder400= @FileAddress, havefile400 = 1 WHERE id = @OrderID Maticsof ...
- python-->基础-->001-->基本模块使用汇总
一.python调用linux系统命令模块 import os import commands 例如,调用系统命令执行ping操作: 使用commands模块方法:>>> impor ...
- SMTP的相关命令
SMTP是Simple Mail Transfer Protocol的简写. 邮件是日常工作.生活中不能缺少的一个工具,下面是邮件收发的流程. Image 邮件的发送,主要是通过SMTP协议来实现的. ...
- 本地调试webapi
1.新建iis站点,路径关联到代码站点下D:\work\易解科技\程序源码\YQJ\trunk\YQJOpenAPI\YQJOpenAPI 2.vs以管理员身份启动 3.附加到进程 w3wp.exe ...