1

I want to run selenium tests only if a special flag is provided e.g.

mvn -DrunUiTests=true test

I am using Junit5. I tried already:

  • An env varible. But the tests will be instantieted anyway.
  • An home made annotation
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@ExtendWith(DisableUITests.class)
public @interface UITest { }

Where DisableUITests returns ConditionEvaluationResult.enabled if a env variable is set. But maven run on console ignores that annotationn.

Furthermore it tryied the surefire plugin:

           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M3</version>
                <configuration>
                    <excludes>
                        <exclude>**/*UiTest.java</exclude>
                    </excludes>
                </configuration>
            </plugin>

But then I am not able to start the tests my own :-)

  • Have you considered running these tests in the `integration-test` phase instead? This uses the [Maven Failsafe Plugin](https://maven.apache.org/surefire/maven-failsafe-plugin/) in a later build phase after `package`. – Steve C Sep 26 '19 at 10:29

1 Answers1

0

I'm afraid the only condition that surefire plugin can consider is file/test name patterns. However you can use the approach described in Conditionally ignoring tests in JUnit 4 where you would test required system property as Assumption

Alexey R.
  • 8,057
  • 2
  • 11
  • 27