简体   繁体   English

通过命令行运行NUnit测试时使用runsettings文件

[英]Using runsettings file when running NUnit tests via command line

I created a runsettings file which looks like this 我创建了一个看起来像这样的运行设置文件

<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
  <TestRunParameters>
    <Parameter name ="environment" value="PROD" />
  </TestRunParameters>
</RunSettings>

And then in my TestSetup portion (using LeanFT for UI tests) I specify that the target environment is contained under a paramater called environment 然后在我的TestSetup部分(使用LeanFT进行UI测试)中,指定目标环境包含在称为环境的参数下

string env= TestContext.Parameters["environment"];

This doesnt seem to work, and I am not getting any particular error messages. 这似乎不起作用,并且我没有收到任何特定的错误消息。 Is this the right way to do this, or is there an easier way to just use Environment and something I pass into the command line. 这是执行此操作的正确方法,还是有一种更简单的方法来仅使用Environment和我传递给命令行的内容。

You should be more specific than "via the commandline" since there are a number of ways that folks run NUnit tests from the command-line. 您应该比“通过命令行”更具体,因为人们可以通过多种方式从命令行运行NUnit测试。

If you are using the nunit3-console.exe runner, you pass run parameters to the framework using the --params option, for example: 如果使用的是nunit3-console.exe运行程序,则使用--params选项将运行参数传递给框架,例如:

nunit3-console my.test.dll --params "environment=PROD"

The .runsettings file is an artifact used by Visual Studio and recognized by the NUnit VS adapter, but not by NUnit itself. .runsettings文件是Visual Studio使用的工件,可被NUnit VS适配器识别,但不能被NUnit本身识别。

You can use that from the command-line as well, using vstest.console.exe . 您也可以在命令行中使用vstest.console.exe来使用vstest.console.exe If that's what you are using, you want the /Settings option in order to specify the file. 如果这是您正在使用的,则需要/Settings选项以指定文件。

Two answers for the price of one! 两个答案为一个的价格! But if you are using neither nunit-console nor vstest.console you'll have to ask again. 但是,如果您既不使用nunit-console 也不使用 vstest.console ,则必须再次询问。 ;-) ;-)

Within a test could you use the following to write all your settings 在测试中,您能否使用以下内容编写所有设置

   foreach (var name in TestContext.Parameters.Names)
   {
       Console.WriteLine("Parameter: {0} = {1}", name, TestContext.Parameters.Get(name))
   }

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

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