简体   繁体   English

Nunit测试套件从脚本运行

[英]Nunit Test Suite Run From Script

I'm using Nunit 3.12, and I'd like to run various subsets of my tests from a script. 我正在使用Nunit 3.12,我想从脚本运行测试的各个子集。 For example, I know Nunit supports various attributes, and I can run various classes using the test window in Visual Studio, or test playlists. 例如,我知道Nunit支持各种属性,并且可以使用Visual Studio中的测试窗口或测试播放列表来运行各种类。

However, is it possible to specify a subset of tests via script and execute from command line? 但是,是否可以通过脚本指定测试的子集并从命令行执行? Nunit Console appears to be a console test runner, but it's not clear if it's intended for this kind of scripted use. Nunit Console似乎是控制台测试运行程序,但尚不清楚它是否打算用于这种脚本用途。 In Python with Pytest, you can run run pytest from a Python script , and in Java, with Junit, you can run particular classes from a gradle job, or on the command line with an argument file . 在带有Pytest的Python中,您可以从Python脚本运行run pytest ,而在Java中,可以通过Junit运行gradle作业中的特定类,或者在命令行中运行带有参数文件的类

I'm wondering because I'd like to set up particular sets of tests to be run in a build pipeline -- run the smoke tests over every dev build, but run the longer regression tests over every qa build, for example. 我想知道是因为我想设置要在构建管道中运行的特定测试集-例如,对每个开发构建都运行冒烟测试,但是对每个qa构建都运行更长的回归测试。 Mostly this could be split up by classes, but I do also have attributes currently decorating different test inputs, etc. 通常,这可以按类划分,但是我确实具有当前装饰不同测试输入等的属性。

UPDATE #1: 更新#1:

I'm targeting .NET framework 4.6.1. 我的目标是.NET Framework 4.6.1。

You can use NUnit.ConsoleRunner to accomplish this -- the console runner takes .txt file containing namespaces of test cases to run. 您可以使用NUnit.ConsoleRunner来完成此操作-控制台运行程序将使用包含测试用例命名空间的.txt文件来运行。 You can create multiple .txt test list files to use as build parameter to run automation against different test lists. 您可以创建多个.txt测试列表文件用作构建参数,以针对不同的测试列表运行自动化。

For pipeline, you'll also need to do scripting to build your project and restore package references. 对于管道,您还需要执行脚本来构建项目并还原包引用。 I like to use Cake , a C# build scripting tool that integrates with NUnit3. 我喜欢使用Cake ,这是与NUnit3集成的C#构建脚本工具。 Cake builds the project and runs tests directly from the commandline. Cake构建项目并直接从命令行运行测试。

I have a generic Cake / NUnit3 build script on my GitHub that can serve as a starting point for you. 我在GitHub上有一个通用的Cake / NUnit3构建脚本,可以作为您的起点。 You'll need to install Cake to get started and familiarize yourself with their documentation here . 您需要安装Cake才能开始使用,并在这里熟悉其文档。 Hope this helps -- let me know if you have additional questions about this. 希望对您有所帮助-如果您对此还有其他疑问,请与我们联系。

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

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