How to identify slow unit tests when using maven-surefire-plugin in parallel mode?

后端 未结 1 1807
广开言路
广开言路 2021-01-04 09:36

With a view to managing / reducing our build times, I want to identify which unit tests are taking the most time - in a parallel test environment using the maven-suref

相关标签:
1条回答
  • 2021-01-04 10:15

    Adding to the Maven Surefire Plugin configuration the reportFormat entry and setting its value to plain (instead of the default brief) would give you elapsed time per method.

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19</version>
                <configuration>
                    <argLine>-Xmx2G -XX:MaxPermSize=1G -XX:-UseSplitVerifier</argLine>
                    <failIfNoTests>false</failIfNoTests>
                    <parallel>classesAndMethods</parallel>
                    <useUnlimitedThreads>true</useUnlimitedThreads>
                    <reportFormat>plain</reportFormat>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    Output with default reportFormat (brief):

    -------------------------------------------------------
     T E S T S
    -------------------------------------------------------
    Running com.sample.mocking.InternalServiceTestCase
    Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.241 sec - in com.sample.mocking.InternalServiceTestCase
    

    Output with plain value:

    -------------------------------------------------------
     T E S T S
    -------------------------------------------------------
    Running com.sample.mocking.InternalServiceTestCase
    Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.187 sec - in com.sample.mocking.InternalServiceTestCase
    test(com.sample.mocking.InternalServiceTestCase)  Time elapsed: 0.005 sec
    mockTest(com.sample.mocking.InternalServiceTestCase)  Time elapsed: 0.17 sec
    mockTestFailureTollerance(com.sample.mocking.InternalServiceTestCase)  Time elapsed: 0.007 sec
    mockProcessfile(com.sample.mocking.InternalServiceTestCase)  Time elapsed: 0.003 sec
    

    This option may give you further details on tests and execution time.

    0 讨论(0)
提交回复
热议问题