whether
Testcase
How good and perfect written, you want to make sure that the code being tested is executed and is still very difficult. In order to obtain information about this, we can use
JCOVERAGE
.
purpose of usage
JCOVERAGE is just its name, mainly used for code coverage testing. By adding a corresponding instruction in a binary file that is tested, the JUnit is added, and JCOVERAGE can give the code coverage of the tested class and give it to which statements during the test are executed, which are not. Through this information, we can understand the test quality of the test code, and which statements in the test class require special attention (ie those that are not overwritten).
The current version is 1.0.5, you can download from www.jcoverage.com/downloads.html. When actually use, you need to place the class used by JCOVERAGE in the corresponding ClassPath. In this version it depends on the outside and version:
- Bcel 5.1 http://jakarta.apache.org/bcel/
- log4j 1.2.8 http://jakarta.apache.org/log4j/
- getopt 1.0.9 http://gnu.org/
- ORO 2.0.7 http://jakarta.apache.org/oro/
usage
1. JCOVERAGE can be used with Ant to automate this process. Basic usage:
- Compiling the JUnit code for the test class and the corresponding test class.
- Use
- Execute the JUnit code for code override test. This step is to be aware that the test class that needs to be injected into the instruction is needed to be loaded earlier than the test class required for unit testing. To ensure this, you need to use
- Report of overwriting tests using
2. Example:
javac>
javac>
fileset> path>
fileset>
inStrument>
This ensures that they have been equipped earlier than testing, and the instructions work. ->
claspath>
batchtest>
junit>
3. The ANT Task tags provided by JCOVERAGE are:
-
-
-
fileset>
merge>
-
example 1 :
Example 2
check>
The name is in line with the XPToolkit.jcoverage. * The branch coverage of the pattern reaches 85%, and the overlay coverage of 95% is 95%, and the cable coverage is 95%.
checklist
Need to pay attention to the question: Taking JCOVERAGE:
- The class that is injected into the instruction of the JCOVERAGE must be a class compiled in Debug mode. It is recommended to separate the storage of classes compiled using the Debug mode to the final product directory.
- Use the class of
- For items that use AOP (such as AspectJ) technology, JCOVERAGE cannot be applied to classes that have already added aspect information.
- The code coverage tool is just a guided opinion, do not excessively dependent and believe in its results.