Search code examples
javaseleniumjunit4

How to run different test suits by parameter?


I have some code running selenium testing. My tests run with Junit 4.12 with @RunWith and @Suite annotations. Up until now I was running the test suite with 3 separate tests on one machine. I now have to run my tests on multiple machines some are setup without a GPU. As one of my tests depends on a GPU so I would like to be able to automatically omit the test when I run the suit on machines without GPU.

here my code at the moment -

@RunWith(Suite.class)
@Suite.SuiteClasses({
        Test1_With_GPU.class,
        Test2_Without_GPU.class,
        Test3_Without_GPU.class
})

is there any way to have another set of suits:

@Suite.SuiteClasses({
        Test2_Without_GPU.class,
        Test3_Without_GPU.class
})

and run the suite according to systemProperties in pom.xml

<systemProperties>
    <property>
         <name>runWithGPU</name>
         <value>${runWithGPU}</value>
   </property>
</systemProperties>

so that when runWithGPU==True I will run the first suite, but when runWithGPU==False I will run the second suite?


Solution

  • I've figured out how to skip the test by adding the following line in my code:

    public void test() {
            assumeThat(System.getProperty("RUN_TEST_1"), CoreMatchers.is("True"));
            // rest of code here
    }
    

    Now my code run skips the test if I run mvn test -DRUN_TEST_1=False.

    Hope this will help someone in the future.