Optimizeit Code Coverage overview
This article introduces some of the main features of Optimizeit Code Coverage to make you a brief understanding. If you want to know more, please see the Optimizeit Code Coverage user manual. You can also view all documents from the OptimizeIt Code Coverage.
If you have any questions, please feel free to contact Borland Technical Support.
Test a Java program
Optimizeit Code Coverage is the overlay information of collecting programs from the virtual machine running program.
First run a Java program, you need to install a Java virtual machine. Optimizeit Code Coverage default installation configuration JDK 1.4 or
1.4.1. If you want to use additional virtual machines, you can view how the Optimizeit Code Coverage user manual adds a new virtual machine section.
Launch application
Optimizeit Profiler can be used to test any type of Java program, including standard applications, apps, servlets, JSP, EJB, etc.
The demo in this article is a test object with a bank account program that is included in the QuickTour directory of Code Coverage. Banking.java is the primary class, which is used to create and process different types of transactions required by users. Generally, each user has four bank accounts:
§ Settle account (C) (CHECKING Accent)
§ Savings Account (P) (P) (P) (P)
§ Self-study loan return account (S) (Student Loan Repayment Savings Account)
§ Car loan return account (L) (car loan repayment account)
Bank accounts have the following common attributes:
§ Account Number (Account Number)
§ Holder name (Owner's name)
§ Blatry (Current Balance)
Counting the account does not have interest, there is no minimum amount, and interest will not be generated. For savings accounts, interest occurs when the amount is stored, but the balance of the account is greater than $ 500. Savings accounts are also used to prevent overdraft from occurring in the settlement account. If the amount of extracted from the account account is greater than the current balance, then it will automatically transfer from the basic savings account to the accounting account. Basic savings accounts per processed transaction amount requires not less than $ 15.
Suppose we have tested Banking.java using Juint:
§ BankAccountTest1 provides a test of processing that enables transactions through the Banking class. Run this test by code coverage, you can check the coverage of the Banking.java class through BankAcCountTest1. The goal we test is 100% coverage Banking class. Code coverage provides class name and method information for the Banking.java class so you can find how much code from the source code is not performed by BankAccountTest1.
§ BankAccountTest2 is used to prove that 100% of the Banking class can be covered by Code Coverage.
The following test runs through JUnit Testrunner. You can download the latest version of JUnit from www.junit.org. The entire test process is completely completed through Code Coverage.
Download JUnit and extract them to your local disk. Open Optimizeit Code Coverage. If it is open, Optimize is automatically opens the editing setting window. If Optimize is already opened, you can select New from the menu file, and the window will pop up. In the Program Type box, select Application. Enter junit.swingui.teestrunner in the Program Main Class or Jar File box. Click the Browse button to select the program's work directory, select the installation directory of JUnit. Code Coverage automatically returns to the editing setting window. Click Change under Class Path. In Class Path Chooser, open to JUnit installation root directory and select JUnit.jar files. Click the down button to add junit.jar to the classpath. Open to the Optimizeiit Coverage Quicktour and select the / doc / code_coverage / quicktour directory. Click the Down button to add it to the classpath. Click OK to return to the editing setting window. Click the Change button under the Source Path window. In the Source Path Chooser window, open to the Optimizeit Coverage Quicktour directory and select the / doc / code_coverage / quicktour directory, and then click the Down button to join the source code path. Click OK to return to the editing setting window. This way you can see the source code without having other configurations during the test. The editing setting window returned at this time is as follows: You can select the filter tab to select the class to analyze the coverage of the coverage in the filter window. The default setting is to exclude all Java core code classes. And confirm that all JUnit classes have been excluded. The default exclusion list should contain junit. *. Click the Virtual Machines tab, you can choose different JDK. Click the Start Now button. The Edit Settings window is automatically closed. Optimizeit Code Coverage automatically loads the JUnit Testrunner application.
View class code coverage
This section describes the code coverage of class tests by different methods.
In JUnit, you do not select RELOAD CLASSES EVERY RUN. Click the omitial button on the right side of the Test Class Name. In the pop-up Test Selector window, select BankAcCountTest1, and then click OK.
Click the Run button to perform BankAccountTest1. You will see green scroll bars under the button, prove through all the tests. After the program runs, the Optimizeit Code Coverage will display all the already loaded classes in the virtual machine in real time, and display the coverage of their respective code.
Yellow horizontal stroke indicates the coverage of each class. You can use two ways to view this information. For example, click the Detection button from the toolbar
Open the detection window. Select SHOW LINE COVERAGE. This will add two columns in the table. As follows:
The MISSED LINES list indicates that there is a number of rows and class of the class in the selected class. For example, the Banking class has 217 lines of code, and the 20 line code is not executed, and the code coverage is 90.78%. Click the Detection button to select Show All Accessible Classes. This will display the classes that are not loaded into the virtual machine in the window. You can see the new line in the window, classname is the BankAcountTest2 displayed by the italic, and the code coverage is displayed "Class Not Loaded". Click the tag button in the toolbar
To reset the DIFF column. The MISSED LINES DIFF column will also be reset (the number of MISSED LINES DIFF columns is reset to the total number of credits, indicating that all rows are not overwritten). Using tags can understand which class is used when you perform one of the programs. You can make a mark before you do not perform a certain action, then proceed to the operation, which automatically generates a new code coverage record, comment, and tag records. View method coverage
Our goal is also to achieve 100% of the Banking class. From the Class Coverage window, we can see that even if the JUnit's test results show 100% success but still only covers 90.78% of the Banking class. To analyze more clearly, we use methods to overwrite views to view code coverage:
In the class overlay table, select the Banking class, then click the show method button on the toolbar or double-click the row directly. Optimizeit Code coverage opens to the method coverage window:
Above the window shows all methods lists in the Banking class and their execution override, the number of lines called the number and the number of lines that are not executed, the total number of lines. The source code of the class is displayed below the window.
Click the ParsEarguments method in the method list. The source code window automatically scrolls to the code line of the method, you can see that the value of the Call column in some rows is 0, indicating that the re-being called. There are no numbers in the Call column, such as a comment line, will not generate bytes in the class file. Click the Detection button on the toolbar to open the detection window, select Show Method Signatures. This will see the features of all classes in the Banking class. Select Show Difference in the detection window. Optimizeit adds new columns:
The Invocation # DIFF column indicates the number of times the method is executed since the last mark. Many MISSED LINES DIFF columns. A column (DIFF) is also available after the Calls column in the source code box, and its value indicates the number of times the line code is executed later.
The coverage rate of Parsearguments is 95.45%. If you can find a Calls value of 0 in this method, this corresponds to Banking to process an invalid transaction. The other is a TRANSFER method without reaching 100%, only 95.45%. There is no code that is not executed in the code list in the code list. Corresponding business operations are attempts to take out fundors greater than the current balance from a student loan. In the method overlay table, find the PrintDescription method, the method is displayed in the figure that is not called. Click the Detection button and select the HIGHLIGHT SINCE MARK option. This will be eliminated from the yellow base from all the code already executed, because since the last marked, the code in the Banking class is not executed. Click the Detection button and select the Real Time option. This OptimizeIt will display overwrite information even if it is displayed. The method Printscription method is selected in the method overlay table. The code window will automatically scroll to the method. The number of calls in all rows in this method is 0, which is not called until far. Select BankAcCountTest2 in JUnit and click Run. In Optimizeit Code Coverage, you will see the number of calls for various methods in changing. For example, the number of calls of the Parsearguments method has changed. All rows of the PrintDescription method in the code window are displayed in a yellow bottom. From this table we can see that the coverage of the Parsearguments method and the Transfer method reaches 100%. Check the Transfer method and remove the HIGHLIGHT SINCE MARK item from the detector. Such a code in the previous test in the source code table is now displayed in the yarn color:
Click the Class Overwriting button on the Toolbar or select File | Class from the menu to switch to the class overlay view. The coverage of the Banking class has reached 100%. View test results
Optimizeit Code Coverage provides several different ways to view test results, you can overwrite data to the HTML file from the current class override view or method override. You can also output the two types of information to the HTML file at the same time.
1. In the process of running, select the Banking class, click Show Method Coverage
Button Go to the method overlay window.
Click Menu File | Export to open the output window. Select Method and Source Code Coverage in the Export drop-down box. In the FileName box, click the Browse button to select the location you want to store the report. Enter the report name at the end of the filename box. Enter the comment message in the Comments box.
Click OK, Optimizeit will output the result to the defined HTML file and open automatically:
If you want to generate a report of the test program, click GENERATE REPORT on the Toolbar
Button. The window opened as follows:
Select the directory of the save result and enter the file name. Check all the options listed in Options, click the Write Report button. Optimize will automatically generate reports to the specified directory and automatically add date and time information after the file name and automatically open:
Click Stop Java Program
Stop test. Click Menu File | Save to save the current setting.
Save (and merging) test results
Code Coverage not only views overwriting information in real time during use, but also provides a function of saving and associating test results. In this section, let's create a snapshot of runtime information, then get a complete program test result by merging:
From the menu file | Open, select the previously saved scheme or from the menu file | Open RecentT to select the settings you just saved. Click Start Now to start running Junit. Run BankAcCountTest1 in JUnit. It is noted that the Reload Classes option in the Junit window is not selected. Click Show Class Coverage
The button is switched to the class overlay window. Select File | Generate Snapshot from the menu, open the Generate Snapshot window:
Select a directory and enter the name of the snapshot in the name box, and then click the Write Snapshot button. Click the Mark button on the toolbar to mark the current class. Return to JUnit, select BankAcountTT22 from Test Selectto and then click Run. Return to Optimizeit Cavage Coverage, you can see that the percentage overlay information of the Banking class in the window of BankAccountTest2 becomes 100%, saving this information as a snapshot. Open the DOS window, set the Optimizeit installation directory to the current directory, and there is an executable program called Snapmerge in this directory. Enter: snapmerge mergefile.snp snapshot1.snp snapshot2.snp snapshot1.snp snapshot2.snp snapshot2.snp snapshot1.snp snapshot2.snp
Here mefile.snp is a snapshot after the merger, and snapshotx.snp is the snapshot name to merge together. Note that the file name in the command line should contain .snp suffix.
Return to Code Coverage and click Stop to stop the virtual machine. After the virtual machine is stopped, Code Cover will open a snapshot. Click Menu File | Open Snapshot to open a merged snapshot. The code coverage is shown below:
You can merge multiple snapshot files together. This is very useful. For example, if it is used by different people to test a different function, then each person's test results are combined into a complete overlay test result of the product in the same snapshot file.
This will be hereby. If you know more about the Code Coverage operations and features, see the Optimizeit Code Coverage user manual. Translation: wyingquan@hotmail.com
2004-11-8
If you are interested in this article or a white box test, please visit http://groups.yahoo.com/group/whiteboxtestcn/, join the member, you can download the complete content of this article (format is a Word document with a picture), There are also some other white box test tools and related discussion.