Adding Method Inputs
Jtest allows you to add both primitive and complex method inputs. The procedure for adding inputs varies depending on the type of input that you want to add.
Important: Method inputs are added to arguments in the Class Test Parameters window.
If you are in the Class Testing UI, you can open this window by clicking the Class button.
If you are in the Project Testing UI, you can open this window by performing the following steps:
- Click Project.
- Right-click the Classes in Project> <name of class to which you want to add inputs> branch, then choose Edit Class Test Parameters from the shortcut menu.
Adding Primitive Inputs
There are two ways to define your own primitive inputs for methods under test:
Using the Method's Class Test Parameters Tree Node
To add primitive inputs directly to the method's Class Test Parameters Tree node:
- Open the Class Test Parameters window.
- In the Class Test Parameters window, go to Dynamic Analysis> Test Case Generation> User Defined> Method Inputs to view a list of all methods in the class.
- Open the node associated with the method whose inputs you want to define.
- Right-click the argument that you want to define an input for, then choose Add Input Value from the shortcut menu.
- In the text field of the box that opens, type the input that you want to use, then press Enter to save this value.
Using the Repository
To add a primitive inputs using the repository, you must complete two main tasks:
- Add constants to the inputs repository.
- Add the appropriate repository inputs to the appropriate method argument.
Adding Constants to an Inputs Repository
To add a constant to an Inputs Repository:
- Open the Class Test Parameters or Global Test Parameters window.
- In the Test Parameters window, go to Dynamic Analysis> Test Case Generation> Common> Inputs Repository.
- Right-click Inputs Repository, then choose Add Constant from the shortcut menu. The Add Constant window will open.
- In the Add Constant window, enter the type of the constant (e.g. int) in the Type field, the name of the constant (e.g. FIVE) in the Name field, and the value of the constant (any valid Java expression-- e.g., 5) in the Value field.
-
- Choose Options> Save.
- Choose Options> Quit.
Using Repository Inputs
When you want to add repository inputs to an argument:
- In the Class Test Parameters window, right-click the node associated with the argument that you want to add an input value to (this node is at Dynamic Analysis> Test Case Generation> User Defined> Method Inputs> <Method Name>). A shortcut menu will open.
- From the shortcut menu, choose either Add From Local Repository (if the input is in the local repository), or Add From Global Repository (if the input is in the global repository), then choose the desired input.
Adding Non-Primitive Inputs
There are two ways to add non-primitive (object-type) inputs to a method:
Using a .java Class File
The objects to be used for the user-defined test cases can be defined in any .java class. Jtest can use those inputs as long as:
- The class that is defining the input object is in the classpath.
- You import each input class using the Dynamic Analysis> Test Case Generation> Common> Imports node of the Class Test Parameters tree.
For an example of how to add inputs using .java class files, see <jtest_install_dir>/examples/blackbox/inputs/README.
Using the Repository
To add a non-primitive input using the repository, you must complete two main tasks:
- Define a method that will instantiate and set up the desired object input, then add it to an Inputs Repository.
- Add the appropriate repository input to the appropriate method argument.
Adding Methods to an Inputs Repository
To add a method to an Inputs Repository:
- Open the Class Test Parameters or Global Test Parameters window.
- In the Test Parameters window, go to Dynamic Analysis> Test Case Generation> Common> Inputs Repository.
- Right-click Inputs Repository, then choose Add Method from the shortcut menu. The Add Method window will open.
- In that window, define a method that creates and returns the desired input values.
- Enter the method declaration (e.g. int sum() ) in the Decl field.
- (Optional) If you want to check the method, choose Save & Check from the Options menu.
- Choose Options> Save.
- Choose Options> Quit.
Using Repository Inputs
When you want to add repository inputs to an argument:
- In the Class Test Parameters window, right-click the node associated with the argument that you want to add an input value to (this node is at Dynamic Analysis> Test Case Generation> User Defined> Method Inputs> <Method Name>). A shortcut menu will open.
- From the shortcut menu, choose either Add From Local Repository (if the input is in the local repository), or Add From Global Repository (if the input is in the global repository), then choose the desired input.
Related Topics
About Black-Box Testing
Performing Black-Box Testing
Adding Test Classes
Specifying Imports
Jtest Tutorials
|