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
4. Integration steps
4.1, the class under test
Note: The class under test should be placed under main, not under test
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)
4.3. Configuring Code Coverage
Select Edit Configurations
Select Code Coverage, then select JaCoCo
Right click and select Run with Coverage
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
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.
Add a sub method test case, and then look at the results.
First, the Method is changed from 1 to 2, and the number of Lines has also increased.
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.
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.