JCOVERAGE uses a concise manual

zhaozj2021-02-16  47

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 to add JCOVERAGE instructions to the binaries of the tested class. To ensure that this process is effective, set the debug property set to YES when compiling the test class.

- 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 to make the test class of the injection instruction before the test class.

- Report of overwriting tests using .

2. Example:

This ensures that they have been equipped earlier than testing, and the instructions work. ->

3. The ANT Task tags provided by JCOVERAGE are:

- Injects JCOVERAGE instructions in the class binaries. Note: You must be a class compiled in Debug mode.

- Generates a JCOVERAGE report, the default format is HTML. You can also generate an XML format to make it easy to apply a customer-defined XSLT to generate a report of other formats. Generate reports in XML format:

- , integrating multiple output files generated by JCOVERAGE. The actual operation process of the entire JCOVERAGE is: First, JCOVERAGE generates a new class to the test class injection instruction, and the class that is injected into the instruction generates an output file (suffix SER) during the JUnit run, and finally generates a report according to the output file. If there are multiple output files, JCOVERAGE provides to integrate these files, and finally, from the integrated files. Usage:

- , check whether the test reaches the set standard, which can be used with . Example:

example 1 :

means that the branch coverage needs to reach 95%, and the coverage rate is 95%.

Example 2

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 , and it is best to separate with the source class.

- 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.

转载请注明原文地址:https://www.9cbs.com/read-24835.html

New Post(0)