I want to run test classes whose name end with ResourceTest.java, so I defined following execution.
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <excludes>
            <exclude>**/*.java</exclude>
        </excludes>
    </configuration>
    <version>2.12.2</version>
    <executions>
        <execution>
            <id>resource-tests</id>
            <phase>resource-tests</phase>
            <goals>
                <goal>resource-tests</goal>
            </goals>
            <configuration>
                <includes>**/*ResourceTest.java</includes>
                <!-- <exludes>**/*.java</exludes> -->
            </configuration>
        </execution>
    </executions>
</plugin>
But I'm not sure how to run this, I've searched a lot and I'm missing something.
I tried surefire:test, it skipped all the test cases as defined in above configuration. So, I tried surefire:resource-tests, maven is saying no goal is not defined.
I'm using eclipse to run my maven build, by passing these parameters. How can I run by the execution id?
How to select a specific execution when running with surefire:test when I've mulltiple executions defined in my pom?
What am I missing? Any help would be appreciated.
There are several problems with your current configuration :
maven-surefire-plugin to be executed in the resource-tests phase but this phase does not exist. You should delete that declaration to keep the default plugin binding phase, which is test.resource-tests but maven-surefire-plugin does not define such a goal.<includes> element is ill-defined. There should be a <include> tag under it.<configuration> element not for each <executions>.<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.12.2</version>
    <configuration>
        <includes>
            <include>**/*ResourceTest.java</include>
        </includes>
    </configuration>
</plugin>
When you have multiple executions and you want "select" one of them, you can use a profile:
<profiles>
    <profile>
        <id>resource-tests</id>
        <properties>
            <test-classes>**/*ResourceTest.java</test-classes>
        </properties>
    </profile>
    <profile>
        <id>task-tests</id>
        <properties>
            <test-classes>**/*TaskTest.java</test-classes>
        </properties>
    </profile>
</profiles>
with the following plugin configuration:
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.12.2</version>
    <configuration>
        <includes>
            <include>${test-classes}</include>
        </includes>
    </configuration>
</plugin>
With such a configuration:
mvn clean test -Presource-tests, only the classes matching **/*ResourceTest.java will be testedmvn clean test -Ptask-tests, only the classes matching **/*TaskTest.java will be testedIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With