尽管forkCount是>,但在surefire 2.16中没有观察到分叉。 1

时间:2015-08-04 08:32:27

标签: maven junit junit4 maven-surefire-plugin

这是我的设置:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.18.1</version>
            <configuration>
                <forkCount>1C</forkCount>
                <redirectTestOutputToFile>true</redirectTestOutputToFile>
                <reuseForks>true</reuseForks>
                <argLine>-Xmx256m</argLine>
            </configuration>
        </plugin>

我正在使用junit 4.12:

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
        <version>4.12</version>
    </dependency>

但是在启动我的测试时,我看不到任何分叉? 我在linux上使用maven 3.2.5和JDK 8。

1 个答案:

答案 0 :(得分:1)

我运行了一些调试(mvn -X test),结果发现尽管使用版本4.12,但是确定并未使用junit47提供程序,而是junit4提供程序。不幸的是,junit4提供商似乎无法处理forkCount

浏览文档我可以找到以下算法来选择提供者:https://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html 必须设置parallel属性才能激活junit47提供商(有点反直觉......)。

我为此创建了一个JIRA:https://issues.apache.org/jira/browse/SUREFIRE-1171

现在我的配置如下:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.18.1</version>
            <configuration>
                <parallel>classes</parallel>
                <threadCount>1</threadCount>
                <forkCount>1C</forkCount>
                <redirectTestOutputToFile>true</redirectTestOutputToFile>
                <reuseForks>true</reuseForks>
                <argLine>-Xmx256m</argLine>
            </configuration>
        </plugin>

修改

原来,redirectTestOutputToFile现在变得毫无用处......我已经对现有问题添加了评论:https://issues.apache.org/jira/browse/SUREFIRE-703?focusedCommentId=14653289&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14653289

我想出了以下内容,以便同时使用forks和redirectTestOutputToFile

       <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.18.1</version>
            <dependencies>
                <dependency>
                    <groupId>org.apache.maven.surefire</groupId>
                    <artifactId>surefire-junit47</artifactId>
                    <version>2.18.1</version>
                </dependency>
            </dependencies>
            <configuration>
                <forkCount>1C</forkCount>
                <redirectTestOutputToFile>true</redirectTestOutputToFile>
                <reuseForks>true</reuseForks>
                <argLine>-Xmx512m</argLine>
            </configuration>
        </plugin>
相关问题