Domanda

I have a project that has unit and integration tests. I have two test suites:

@RunWith(ClasspathSuite.class)
@ClasspathSuite.ClassnameFilters({ ".*Test", "!.*IntegrationTest", "!.*ResourceTest", "!.*DAOTest" })
@ClasspathSuite.SuiteTypes({ SuiteType.JUNIT38_TEST_CLASSES, SuiteType.TEST_CLASSES, SuiteType.RUN_WITH_CLASSES })
public class AutoTestSuite {
}

which runs 70 tests in about 20 seconds

@RunWith(ClasspathSuite.class)
@ClasspathSuite.SuiteTypes({ SuiteType.JUNIT38_TEST_CLASSES, SuiteType.TEST_CLASSES, SuiteType.RUN_WITH_CLASSES })
@ClasspathSuite.ClassnameFilters({ ".*IntegrationTest" })
public class IntegrationTestSuite {
}

which runs 99 integration tests in about 80 seconds.

This is fine, but when I try to run my maven build locally and inside Jenkins the test numbers are between 12-18 minutes minutes to run 348 tests. Clearly my pom.xml, even accounting for jacoco to inspect. Can anyone see what is wrong with the following that I invoke with "mvn clean package:

<plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.6.0.201210061924</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <propertyName>jacoco.argLine.unit</propertyName>
                            <destFile>${jacoco.destFile.unit}</destFile>
                        </configuration>
                    </execution>
                    <execution>
                        <id>pre-integration-test</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <propertyName>jacoco.argLine.it</propertyName>
                            <destFile>${jacoco.destFile.it}</destFile>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- UNIT tests only with mvn clean test -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${version.surefire}</version>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.surefire</groupId>
                        <artifactId>surefire-junit47</artifactId>
                        <version>${version.surefire}</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <argLine>${jacoco.argLine.unit}
                        -Dfile.encoding=${project.build.sourceEncoding} -Xmx512m
                    </argLine>
                    <forkMode>always</forkMode>
                    <parallel>classes</parallel>
                    <includes>
                        <include>**/*.class</include>
                    </includes>
                    <excludes>
                        <exclude>**/*.IntegrationTest.java</exclude>
                    </excludes>
                </configuration>
            </plugin>
            <!-- INTEGRATION tests that are run with "mvn clean verify" -->

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>${version.surefire}</version>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.surefire</groupId>
                        <artifactId>surefire-junit47</artifactId>
                        <version>${version.surefire}</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <forkMode>pertest</forkMode>
                    <reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
                    <argLine>${jacoco.argLine.it}
                        -Dfile.encoding=${project.build.sourceEncoding} -Xmx512m
                    </argLine>
                    <includes>
                        <include>**/*.class</include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>verify</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

Is there a reason the tests appear to be duplicated and taking so long?

È stato utile?

Soluzione

I'm not a maven or surefire expert, but I think the surefire plugin executes every test file it finds in under your test directory. This means the default configuration doesn't need test suites. Surefire finding and then running your test suite PLUS your other tests could be the cause of the 2x the number of tests to be run. But I don't know why it would take more than twice as long to run.

If this is the case, you can tell surefire to only run your test suite:

<configuration>
  ...
  <includes>
    <include>AutoTestSuite.java</include>
  </includes>
</configuration>

instead of **/*.class

EDIT: Because Jacoco has already instrumented the classes you need to use

<configuration>
  ...
  <includes>
    <include>AutoTestSuite.class</include>
  </includes>
</configuration>

instead otherwise you don't run the instrumented version.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top