How to specify custom parameters, using xunit.runn

2019-05-11 12:42发布

问题:

I have a C#/Selenium/Specflow test suite which I am running using Jenkins using xunit.console.exe. I need to point these tests to different environments (Test/QA/Prod etc.) and would like to use a command line parameter.

The batch command I am calling is: "%WORKSPACE%\packages\xunit.runner.console.2.1.0\tools\xunit.console" "%WORKSPACE%\[MyProject]\bin\Debug\eDC6.Test.Specs.dll" -xml test_output.xml

and would like to include an extra parameter like: "-env=PROD" to point that job to a specific environment.

I am open to better ways to do this.

回答1:

IIRC I asked and self-answered this very question as a feature request in xunit's forums in the codeplex era, pre-2010 but can't locate it atm (perhaps I was asking in the context of CodeRush's test runner). Either way, the above was the answer at that time, and it still makes sense as it's test-runner and CI tool neutral.

This is commonly addressed by environment variables, i.e. use GetEnvironmentVariable.

One thing to consider is that people who want to use runners such as Visual Studio will then need to adjust accordingly. .NET Core has intrinsic support for having an environment selector of this nature, which may also be a useful approach as it's likely to be exposed in editors and other tooling over time.

Finally, the lowest level hack may be to be sticking it into .config settings, i.e., the <DllName>.dll.config and doing the necessary to pass it through there.



回答2:

For this solution the extra command-line gives me more flexibility:

"%WORKSPACE%\packages\xunit.runner.console.2.1.0\tools\xunit.console" "%WORKSPACE%[MyProject]\bin\Debug\eDC6.Test.Specs.dll" -TargEnv QAConfig.json - xml test_output.xml