通过命令行将参数传递给 NUnit [英] Pass parameters via the command line to NUnit

查看:37
本文介绍了通过命令行将参数传递给 NUnit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过命令行将值传递给 NUnit 测试?

Is it somehow possible to pass values to NUnit tests via the command line?

我的测试使用特定的 URL.我在不同的 URL 上有不同的代码实例,并且想通过命令行指定 URL.文件 App.config 不是一个选项,因为我想通过批处理文件对不同的 URL 运行测试.

My tests use a certain URL. I have different instances of my code at different URLs and would like to specify the URL via the command line. File App.config is not an option, because I want to run the tests for different URLs via a batch file.

推荐答案

NUnit 3 现在允许传递参数.这是用法

NUnit 3 now allows passing parameters. Here is the usage

nunit3-console [inputfiles] --params:Key=Value

来自文档

--params|p=参数

--params|p=PARAMETER

以 NAME=VALUE 形式指定的测试参数,用于测试消耗.多个参数可能是指定,用分号分隔或重复 --params 选项多次.区分大小写.

A test PARAMETER specified in the form NAME=VALUE for consumption by tests. Multiple parameters may be specified, separated by semicolons or by repeating the --params option multiple times. Case-sensitive.

以下是通过代码访问参数的方法:

Here's how you can access the parameter through code:

var value= TestContext.Parameters.Get("Key", "DefaultValue");

这篇关于通过命令行将参数传递给 NUnit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆