Using runsettings file when running NUnit tests via command line

我怕爱的太早我们不能终老 提交于 2021-02-18 17:58:26

问题


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

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.


回答1:


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.

If you are using the nunit3-console.exe runner, you pass run parameters to the framework using the --params option, for example:

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.

You can use that from the command-line as well, using vstest.console.exe. If that's what you are using, you want the /Settings option in order to specify the file.

Two answers for the price of one! But if you are using neither nunit-console nor vstest.console you'll have to ask again. ;-)




回答2:


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))
   }


来源:https://stackoverflow.com/questions/47098041/using-runsettings-file-when-running-nunit-tests-via-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!