简体   繁体   中英

Execute tests with different TestFixture paramenters using NUnit3 console

Does anyone know if it is possible to execute tests with different TestFixture parameteres using nunit3 console? I have the following code:

  [TestFixture(Browser.Firefox)] 
  [TestFixture(Browser.Chrome)]
  public class Tests : BaseTestCase

and I want to execute the tests with the Browser.Chrome setup only. Is it possible to run all tests from a certain dll that have TestFixture parameter = Browser.Chrome?

Thank you in advance for the provided information!

Thank you for the help! I`ve tried the way you suggest but without any success. When I set the properties of the test class, I cannot get "Browser" value runtime. "Browser" contains all properties set to the test and not the one the test is currently running with.

As a workaroung of my problem I found the following solution: I have a method which is used to find all test classes from the assembly with TestFixture "Browser" set to "Chrome". After the class names are found, they are added in a txt file and finally the file looks like this:

TestClass1(Chrome)
TestClass2(Chrome)
TestClass3(Chrome)

When I have such file, I can run the tests with the following command: nunit3-console "TestsDllPath" --testlist="TextFilePath"

The big dissadvantage of this approach is that the method for creating tests list files should be run each time a test class is added.

Two parts to your question:

  1. It's possible to create a fixture in exactly the way you describe. Did you try? The value of the enum will be passed to the fixture constructor, which of course must be written to take such an enum. I haven't tried this so it may be necessary to set it up as an int, but that's an easy change.

  2. Selecting Just one fixture to run should be easy enough if you first figure out the name that NUnit gives to the test represented by the fixture. It will probably be something like "Tests(Chrome) but you should check either using --explore or running the tests and looking at the XML output. Once you know the name, just run it using the --where option. Running all the tests with such an option would be a matter of using --where with a regular expression that picks up those tests.

    If --where "test=~/(Chrome)/" isn't a good enough selector, then I would replace the enum with some const strings you define yourself like "BrowserIsChrome" You can convert those to the enum in your constructor. Just make the strings sufficiently unique that you can test for them in the --where option.

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