0

Could you please advise me on whether or not I can dynamically change Include and Exclude for the Maven Surfire Plugin?

For example:

<build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.18.1</version>
                        <configuration>
                            <includes>
                                <include>**/${param}Spec*.*</include>
                            </includes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>

I would like to have $param passed from the command line when we perform the Maven test command.

Please give advice if you have a solution. I have tried argline and systemProperties

Thanks!

gavsta707
  • 365
  • 3
  • 16
Nghia Do
  • 2,588
  • 2
  • 17
  • 31
  • One of possible solution is using maven [profiles](http://maven.apache.org/guides/introduction/introduction-to-profiles.html) – Ivan Pronin Jul 27 '17 at 20:43
  • see this one :https://stackoverflow.com/questions/7513319/passing-command-line-arguments-from-maven-as-properties-in-pom-xml/7515282 – André Jul 27 '17 at 20:45
  • Why would you like to change that dynamically? Not running all tests(spec*)? – khmarbaise Jul 28 '17 at 22:25
  • 'Profile' won't work for me because the pattern for include/exclude is a unlimited combination. – Nghia Do Aug 01 '17 at 16:17

1 Answers1

0

I don't think there is a way to pass dynamic parameter, but you can use below trick if you have limited combinations of exclusions/inclusions. Trick is using profiles with different combinations like combo1, combo2 etc. Then you can run maven build with specific profile & only those include/exclude will work.

Command = mvn clean package -P combo1

pom.xml

<profiles>
    <profile>
        <id>combo1</id>
        <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.18.1</version>
                        <configuration>
                            <includes>
                                <include>**/Combo1Spec*.*</include>
                            </includes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
    </profile>

    <profile>
        <id>combo2</id>
        <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.18.1</version>
                        <configuration>
                            <includes>
                                <include>**/Combo2Spec*.*</include>
                            </includes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
    </profile>
</profiles>
Ravi K
  • 976
  • 7
  • 9
  • Thanks but Profile won't work for us in this case because actually it is depend on how QA wants to run test cases. – Nghia Do Aug 01 '17 at 16:18