View the new posture of unit test case coverage: IDEA integrates JaCoCo

1. What is IDEA?

The full name of IDEA is IntelliJ IDEA, which is an integrated environment for Java programming language development. IntelliJ is recognized as the best Java development tool in the industry, especially in intelligent code assistants, automatic code prompts, refactoring, JavaEE support, various version tools (git, SVN, etc.), JUnit, CVS integration, code analysis, innovative Features such as GUI design can be said to be extraordinary.

2. What is JaCoCo

JaCoCo is a free, open source Java code coverage tool.

3. Why does IDEA integrate JaCoCo

It is convenient to view the unit test case coverage.

If you want to learn interface automation testing, here I recommend a set of videos for you. This video can be said to be the number one interface automation testing tutorial on the entire network at station B. At the same time, the number of online users has reached 1,000, and there are notes to collect and use. Technical exchanges of various masters: 798478386      

[Updated] The most detailed collection of practical tutorials for automated testing of Python interfaces taught by station B (the latest version of actual combat)_哔哩哔哩_bilibili [Updated] The most detailed collection of practical tutorials for automated testing of Python interfaces taught by station B (actual combat) The latest version) has a total of 200 videos, including: 1. [Interface Automation] The current market situation of software testing and the ability standards of testers. , 2. [Interface Automation] Fully skilled in the Requests library and the underlying method call logic, 3. [Interface Automation] interface automation combat and the application of regular expressions and JsonPath extractors, etc. For more exciting videos, please pay attention to the UP account. https://www.bilibili.com/video/BV17p4y1B77x/?spm_id_from=333.337

4. Integration steps

4.1, the class under test

Note: The class under test should be placed under main, not under test

picture

4.2. Unit test cases

Note: The unit test class (CalcTest) must be in the same package as the tested class (Calc) (com.lemon.testng)

picture

4.3. Configuring Code Coverage

picture

Select Edit Configurations

picture

Select Code Coverage, then select JaCoCo

picture

Right click and select Run with Coverage

picture

Automatic pop-up code coverage interface

4.4. Coverage report

The report is relatively simple, Class means class coverage, Method means method coverage, Line means line coverage

picture

4.5, code coverage

The main unit test case only writes the add method, so the add method is displayed in green, indicating the coverage status, and the sub method is displayed in red, indicating that it is not covered.

picture

Add a sub method test case, and then look at the results.

picture

First, the Method is changed from 1 to 2, and the number of Lines has also increased.

picture

Secondly, the color of the sub method also changes, the if is still red, but the else turns green, indicating that the eles branch is covered.

picture

5. Summary

It can be seen from the above examples that by checking the coverage rate and gradually improving the test cases, the written use cases can at least ensure that each branch is executed, which is better than writing use cases through requirements to troubleshoot potential bugs.

Requirements ≠ code, you can't just write use cases around the requirements, use the JaCoCo coverage tool to write use cases, which is more in line with actual work needs, and saves worry and effort.

Guess you like

Origin blog.csdn.net/caixiangting/article/details/132170611