Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I analyze a junit test suite?

We have a number of unit tests being run with roboletric.

I'm looking to gather metrics on meta data such as longest tests to run, tests that are putting the thread to sleep, basically anything that can be leveraged to improve test run times.

like image 613
RyPope Avatar asked Nov 03 '16 01:11

RyPope


People also ask

What is the use of test suite in JUnit?

Test suite is used to bundle a few unit test cases and run them together. In JUnit, both @RunWith and @Suite annotations are used to run the suite tests. This chapter takes an example having two test classes, TestJunit1 & TestJunit2, that run together using Test Suite.

How do I check JUnit test cases?

We use the assertEquals() method to check the actual result with the expected output. We create the TestRunner. java class to execute the test cases. It contains the main() method in which we run the TestJunitTestCaseExample.

Which interfaces does JUnit provide to view the test results?

JUnit by itself provides two simple mechanisms for reporting test results: simple text output to System. out and its famous Swing and AWT “green bar” GUIs (the AWT GUI being a vestige of JUnit's Java 1.1 support).

Which of the following is correct about test suite in JUnit?

Explanation. Fixture includes setUp() method which runs before every test invocation and tearDown() method which runs after every test method. Q 16 - Which of the following is correct about Test Suite in JUnit? A - Test suite means bundle a few unit test cases and run it together.


1 Answers

Your concern is to reduce testing execution time. You can do it in various ways.

At first, you have to make some decisions that which test cases are mandatory, which test cases need to be run in monthly basis etc.

After defining mandatory test cases, you can create a suite using grouping of your test cases. If you run the groups in parallel, it will reduce a huge amount of time. But your grouping preparation need to be tricky so that every group can take similar type of time. That will be the best way.

For JUnit,

you can use parallel process and thread pooling to how much thread will run your test cases(like 20 threads for 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.

Resource Link: Running junit tests in parallel in a Maven build?

For TestNG, Appium, Jenkins etc

For UI testing you can run multi-browser so that parallelly they can execute more test cases.

You can use multiple node so that at a time multiple node can run and reduce time.

In some cases, you can be more tricky that you will not login in every test cases. There will be a starting point. Every test case will end and will return that starting point. By using this way, we can also reduce time. But it is violation of 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.

A full example using JUnit, JaCoCo and Maven for code coverage is given here: https://softwarecave.org/2014/02/01/using-junit-jacoco-and-maven-for-code-coverage/

Full Code is given here: https://github.com/robertp1984/softwarecave/tree/master/jacoco

like image 111
SkyWalker Avatar answered Oct 13 '22 04:10

SkyWalker