简体   繁体   中英

Executing NUnit test cases with one variable

I have a number of Selenium tests written in C# that are being compiled to a .dll which is being run from the command line using nunit-console.exe.

These tests are working fine for the moment in my testing environment consisting of one site, but I need for the tests to be more general purpose...

The idea behind these tests is that they will be used after a piece of software has been deployed. The software being deployed will set up a site in IIS, and this site will bind to a port that will be automatically assigned based on what is available at the time. I need for my tests to know which port the website will be running on, otherwise it might be testing the wrong site. I am able to identify the port that it is running on by using a return value from the deployment tools I am using.

My question therefore is: Is it possible to pass an argument (website port number for example) to nunit-console that can be used by my already compiled Selenium tests?

The only other solution that I can think of is to build the tests after deployment. I would like to avoid this as the software has already gone through the build phase, and building again seems messy to me especially if our build server (Bamboo) loses visibility of the building process due to it being some custom script within a deployment task.

Thanks in advance.

You can use an environment variable.

In your selenium test you can read it with

var port = System.Environment.GetEnvironmentVariable("SITE_PORT");

and you can set it from different sources, for example batch script or prompt:

set SITE_PORT=<result of command>

AFAIK there is no way to do that in current version of NUnit. One of possible solutions in your case can be using configuration file (which I sometimes use). If you know on which port your tests is running you can save that info into config file and get data from it (using ConfigurationManager): url or wathether you need. YOu'll not spend too much time on changing your tests (you almost don't need to to that, just add method which get url from config file and paste it in correct place =)).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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