Dowemo
0 0 0 0


Question:

I run my JUnit and Mockito tests in a big project. I use them for testing my server-side components that connect to web-service. All these connections require some time and it is not neccessary for them to be executed during the build.

I would like that my tests would be ignored during the build.

I have about 10 classes with tests. So the obvious way is to annotate all the classes with @Ignore. However I should do this every time I commit my code to the project and then re-annotate all tests. Not the very best solution I think.

So is this possible somehow simply ignore all package (let say com.example.tests) with the tests? Or what might be the solution to ignore tests in the build in a simple way?


Best Answer:


You can mention on your build.gradle what packages to exclude from tests

test {
    exclude '**/*IntegrationTest*'
}

same for maven:

must consider this notation:

By default, the Surefire Plugin will automatically include all test classes with the following wildcard patterns:

"**/Test*.java" - includes all of its subdirectories and all Java filenames that start with "Test".
"**/*Test.java" - includes all of its subdirectories and all Java filenames that end with "Test".
"**/*Tests.java" - includes all of its subdirectories and all Java filenames that end with "Tests".
"**/*TestCase.java" - includes all of its subdirectories and all Java filenames that end with "TestCase".
<project>
  [...]
 <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.20</version>
            <configuration>
                <excludes>
                <exclude>*com.example.tests*/*Test.java</exclude>
                </excludes>
            </configuration>
        </plugin>
    </plugins>
</build>
  [...]
</project>

Another option is the old

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
        <skipTests>true</skipTests>
    </configuration>
</plugin>

or even when call it

mvn install -DskipTests



Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs