You can extend a test by calling custom Java code.
Your code might act on one or more input values from the test and return modified values to the test. Custom code input values reside in references or field references, which must already exist in the test. References or field references that are inputs to your code must appear sequentially before your code. Verify that the test contains the references or field references needed as inputs to your code. For details on how to create references and field references, see Creating a reference or field reference.
If your custom code uses external JAR files, you will likely need to modify the Java build path: see Viewing and editing a project's Java build path. In some cases, you can avoid needing to modify the build path manually by running a test before adding your custom code to the test. This is because the first time a test runs, certain classes and libraries required for compilation are added to the build path. For example, you can import Hyades classes needed to create custom events in the execution history if the test to which you have added your custom code has been run previously. But if the test has never before been run, you get import errors because the classes are not named in the project's build path until the test has been executed.
Your code might use external resources: for example, a SQL database or a customer relationship management product. If this is the case, you must configure the custom code such that it works on every computer on which your test is deployed.
Custom code resides in the src folder of
the project containing the test(s) that calls the code. By default, custom
code is put in a package named test inside this folder.
For example, the following figure shows the base Navigator view of two custom
code classes. (The Test Navigator does not display Java source files.)
In this
example, if you add these two custom code classes to your test and choose
to return a value to the test (step 9), Substitute from lists
these two classes in the manner shown in the following figure.
The test package also contains the generated Java code for tests in the project. But, in step 3, you can choose to put custom code in a different package (for example, custom). Separating custom from generated code is recommended, particularly if you use a source control system.
To add custom code:
Parent topic: Extending tests with custom Java code