如何分析 junit 测试套件?

How can I analyze a junit test suite?

我们有一些单元测试是 运行 roboletric。

我正在寻找有关元数据的指标,例如 运行 的最长测试、使线程休眠的测试,基本上是任何可以用来提高测试 运行 次的指标.

您关心的是减少测试执行时间。您可以通过多种方式做到这一点。

首先,你必须做出一些决定,哪些测试用例是强制性的,哪些测试用例需要每月 运行 等等

定义强制测试用例后,您可以使用测试用例分组来创建套件。如果您 运行 并行分组,将减少大量时间。但是你的分组准备需要很巧妙,这样每个小组都可以花费相似的时间。这将是最好的方法。

对于 JUnit,

您可以使用并行进程和线程池来确定多少线程将 运行 您的测试用例(例如 20 个线程用于 5000 tcs)

<build>
    <plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.7.1</version>
        <configuration>
            <parallel>classes</parallel>
            <threadCount>20</threadCount>
        </configuration>
    </plugin>
    </plugins>
</build>

If we calculate here..Suppose, every test case requires 3 sec for execution.

For 5000*3 = 15000sec/3600 = 4.166 hr.

Now, using parallel processing it will take (5000/20)*3 = 750sec/3600 = 0.21hr or `12.5 minutes only.

资源 Link: Running junit tests in parallel in a Maven build?

对于 TestNG、Appium、Jenkins 等

对于 UI 测试,您可以 运行 多浏览器,以便它们可以并行执行更多测试用例。

您可以使用多个节点,这样一次多个节点可以 运行 并减少时间。

在某些情况下,您可能会更加棘手,因为您不会在每个测试用例中都登录。会有一个起点。每个测试用例都将结束,并将 return 作为起点。通过使用这种方式,我们还可以减少时间。但是违反了F.I.R.S.T.

For analyzing, reporting and showing the status of code coverage, execution time, various types of tools are used. JaCoCo is most popular among them. There are also some tools like Cobertura, Arquillian etc.

此处给出了使用 JUnit、JaCoCo 和 Maven 进行代码覆盖的完整示例https://softwarecave.org/2014/02/01/using-junit-jacoco-and-maven-for-code-coverage/

完整代码在这里:https://github.com/robertp1984/softwarecave/tree/master/jacoco