maven build需要很长时间

时间:2013-10-07 23:05:20

标签: java maven jacoco

我有一个包含单元和集成测试的项目。我有两个测试套件:

@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 {
}

在大约20秒内运行70次测试

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

在大约80秒内运行99次集成测试。

这很好,但是当我尝试在本地和Jenkins内部运行我的maven构建时,测试数字在12-18分钟之间运行348次测试。显然我的pom.xml,甚至占jacoco检查。任何人都可以看到我用“ 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>

有没有理由认为测试似乎是重复的并且花了这么长时间?

1 个答案:

答案 0 :(得分:2)

我不是maven或surefire专家,但我认为surefire插件会执行它在测试目录下找到的每个测试文件。这意味着默认配置不需要测试套件。 Surefire查找然后运行您的测试套件加上您的其他测试可能是运行测试数量的2倍的原因。但是我不知道为什么跑的时间会超过两倍。

如果是这种情况,您可以告诉surefire只运行您的测试套件:

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

而不是**/*.class

编辑:因为Jacoco已经为您需要使用的课程进行了检测

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

否则您不会运行已检测的版本。