Quick Start Guide
Jtest fully automates white-box testing, black-box testing, regression testing, and static analysis. The only user intervention required to perform these tests on a class or set of classes is telling Jtest what class or set of classes to test, clicking the Start button, and looking at the test results.
Requirements
General Requirements
You must satisfy all of the following requirements in order to use the minimum Jtest functionality:
- The '.class' files for the classes you want to test must be available. A '.class' file is a compiled Java source. Without a '.class' file, Jtest will not be able to perform any tests.
- The '.class' files must be in a directory hierarchy that reflects the structure of the package, regardless of whether they are in jar files, zip files, or in the file system.
- The classes referenced by the tested '.class' files must be available to Jtest. This is done by adding their location to the CLASSPATH.
- If the '.class' files are in directories, '.zip' files, or '.jar' files, the '.class' files must be accessible by Jtest.
To use full Jtest functionality (Static Analysis, Source Browsing, Design by Contract, etc.) the '.java' source files must be available to Jtest during testing.
Black-Box Testing/Design by Contract Requirements
JDK Requirement
In order for Jtest to perform black-box (functionality) testing and use Design by Contract information, a valid path to your Java compiler must be present in Jtest's Global Test parameters
Jtest automatically determines the path to your JDK by looking at the following variables in the order listed:
- The PARASOFT_JDK_HOME variable.
- The javac PATH environment variable.
- JAVA_HOME, JDK_HOME, JAVAHOME, ...
The first valid variable found is used.
To see what JDK Jtest has detected on your system, click the Global button in the current Jtest UI, then read the value listed in the Common Parameters> Path to JDK directory branch of the Global Test Parameters window that opens.
You can configure Jtest to use a different JDK permanently or temporarily.
To change the JDK permanently:
- Change the PARASOFT_JDK_HOME environment variable in the method appropriate for your operating system.
To change the JDK temporarily:
- Temporarily reset the PARASOFT_JDK_HOME variable at the command line in the method appropriate for your operating system.
- Start Jtest from the command line as described in Running Jtest in Batch Mode.
Contract Requirement
In order for Jtest to automate black-box testing, code must contain Design by Contract-format contracts. For information on adding Design by Contract-format contracts to your code, see Using Design by Contract With Jtest and The Design by Contract Specification Language.
General Testing Procedure
To test your class(es) with Jtest, perform the following steps:
- Open the appropriate UI for your test. The Class Testing UI is used to test a single class; the Project Testing UI is used to test a set of classes.
- The Class Testing UI opens by default when Jtest is launched.
- The Project Testing UI can be opened by clicking the Class Testing UI's Project button.
- If a class or set of classes is already loaded into the UI you are using, click the New button to clear the previous test.
- Use the Browse button to indicate what class or set of classes you want to test.
- Test the class or project for the first time by clicking the Start button.
- The first time you test a class, Jtest will:
- Perform static analysis (if the class's .java source file is available).
- Create and execute white-box test cases that check your code's construction.
- Create and execute black-box test cases that verify your code's functionality (if your code contains Design by Contract-format contracts).
- Review the class test results or project test results, then correct errors found, modify the contracts, or suppress reporting of errors you do not want reported in future test runs.
- Rerun the test when a class is modified (i.e., perform regression testing). To do this:
- Choose File> Open in the UI that you used for the original test, then choose the appropriate .ctp or .ptp file from the file chooser.
- Click Start.
- When the test is run this time (and all additional times) Jtest will:
- Perform static analysis.
- Create and execute white-box test cases that check your class's construction.
- Create and execute black-box test cases that verify your class's functionality (if your code contains Design by Contract-format contracts).
- Perform regression testing by comparing the current test case outcomes with those obtained during the initial test run.
Adding User-Defined Stubs and Test Cases
Jtest also allows you to enter your own stubs and test cases.
Stubs can be added as Stub Classes; for information on adding stubs, see Using Custom Stubs.
Test cases can be added as method inputs or as JUnit-format Test Classes. To add and execute user-defined test cases, perform these additional steps:
- Open the View Test Cases window to view the automatic inputs that Jtest generated during previous test runs.
- In the Class Testing UI, open the View Test Cases window by clicking View.
- In the Project Testing UI right-click the [Class Name] node in the Results panel, then choose View Test Cases from the shortcut menu.
- Design additional test cases.
- Add the user-defined test cases using Test Classes or method inputs.
- Rerun the test by clicking the Start button.
- When the test is run, Jtest will perform all the tests it performed in previous test runs, plus it will execute the user-defined test cases and determine the output for the user-defined test cases.
- Specify the correct outcomes for the user-defined test cases, as well as for automatically-generated test cases, by performing the following tasks for each class and test case:
- View the test case input and outcomes in the View Test Cases window.
- Validate correct outcomes or set the correct value for incorrect outcomes by right-clicking the appropriate outcome node and selecting the appropriate command from the shortcut menu.
- (optional) Specify additional inputs to check.
- When the class is modified, rerun the test by restoring test parameters and clicking the Start button.
- When you rerun the test, Jtest will check for specification and regression testing errors; it does this by comparing validated outcomes with their specified values, and comparing nonvalidated outcomes with their previous values. Jtest will also continue to test for uncaught runtime exceptions and static analysis errors.
Setting Your CLASSPATH
If during testing, Jtest finds ClassNotFoundExceptions or NoClassDefFoundErrors, or if it reports that it could not find the package on "imports", the CLASSPATH is not set properly. If this occurs, you need to set the system CLASSPATH variable to include every class referenced (recursively) by the tested class prior to testing. Check that the CLASSPATH includes the parent directory of the directory hierarchy. For example, if you are testing com.company.MyClass and Jtest reports that it could not find a package referenced by MyClass, it is probably because the 'com' directory is not on the CLASSPATH.
You can override the CLASSPATH environment variable in the Global Test Parameters, the Class Test Parameters, or the Project Test Parameters.
|