Creating or Editing JUnit Tests

To create or edit a JUnit test:

  1. In the menu, click Tests > Details View .
  2. Select a container or folder node in the Tests tree where you want to insert a new test, or select the test that you want to edit.
  3. Click New Child Test (New Child Test) on the toolbar, or click (Edit).

    The New Test/Edit Test dialog box appears.

  4. Type a name and description for the test.
    Note: Silk Central supports HTML formatting and cutting and pasting of HTML content for Description fields.
  5. If you are creating a new test, select JUnit Test from the Type list box. Click Next.

    The JUnit Test Properties dialog box appears.

  6. Specify a valid Java Classpath to use on the execution server.

    We recommend to use a relative classpath. The relative classpath is then expanded to the full classpath on the execution server. By using a relative classpath, changes on the location of the source control profile do not require additional changes to the classpath.

    The relative classpath must point to the root node of the test container containing the JUnit test, for example JUnit_tests. The relative classpath on the execution server is then expanded to include the working folder of the source control profile, for example C:\temp, and the test file names, for example tests.jar. For example, if your tests are packaged in a jar file called tests.jar and additional jar files that are needed for the execution are stored in a sub folder lib, your classpath would be ./tests.jar;./lib/*.

    You can also use a fully qualified classpath. The fully qualified classpath must point to the archive or folder in which the test classes reside.

  7. Optional: In the Test class field, type the fully qualified name of the JUnit test class. If the field is left blank, all tests in the classpath will be executed.
  8. Optional: In the Test method field, type the name of the appropriate test method. The method must be available in the test class. If the Test method field is left blank, all tests that are included in the suite will be executed.
  9. Optional: Set the Java home directory to the installation path of the Java Runtime Environment (JRE). The path must be valid on the execution server on which the test runs.
    Note: JUnit tests can be executed in JRE 1.7 and newer. If you use an older JRE, messages containing java.lang.UnsupportedClassVersionError or Unrecognized option: -javaagent will display in the Messages tab.
  10. Optional: In the JVM options field, you can specify the command-line options. You can specify multiple options, but you have to type them in the right order. For example, to use the client VM and set the maximum size of the heap to 512MB, type -client -Xmx512m. You can also use environment variables, for example -Xmx${MY_MEMORY}.
  11. Check the Record external AUT coverage only check box to get only the code coverage for the application under test that is defined for the execution plan in the Code Analysis Settings portion of Silk Central > Execution Planning > Code Analysis . If the check box is not checked, then the code coverage from the virtual machine that executes the test is recorded too.
  12. Optional: In the Test coverage path field, type the JAR libraries or the specific class files to monitor for code coverage information. Note that the coverage path of the JUnit test is specified here, not the path of the application under test.

    We recommend using the relative coverage path from the test container root node, which is then expanded on the execution server. You can also use a fully qualified path. Use semicolons to separate multiple jar files, as the following examples show:

    • tests.jar;C:\tests\testutils.jar
    • ${testenv}\tests.jar;${testenv}\testutils.jar
    Note: The coverage path setting is disregarded if the Record external AUT Coverage check box is checked.
  13. Click Finish.
Note: Parameters are passed to the Java process as system properties, for example -Dhost_under_test=10.5.2.133. Use the System.getProperty() method to access the system properties. For example, to access the previously passed host_under_test, use System.getProperty(“host_under_test”);.