DevOps Cloud (ADM)
Cybersecurity
IT Operations Cloud
Note: If you are using Silk Central version 15.0 or later, you do not need this workaround with the 3rd party library.
Using the built in JUnit test type of SilkCentral Test Manager (SCTM) is a powerful way to automate the execution of JUnit tests. Nevertheless, it can be quite cumbersome if you have to add a new SCTM test, each time a new test class should be executed.
With the freeware library ClasspathSuite (Johannes Link) you can comfortably get around this maintenance effort and benefit from the power of dynamic test creation with the test package feature of SCTM.
You can download the ClasspathSuite library for free from http://johanneslink.net/projects/cpsuite.jsp (use the library for JUnit 4.5 and above).
The JUnit class specified in SCTM now is no specific test case or suite, but an entry point class annotated with @RunWith(ClasspathSuite.class). When being executed, the class collects all JUnit test classes or a filtered subset of the classes found in the system classpath, or found in a path defined by an SCTM test parameter.
The entry point class is the only place where a dependency to the ClasspathSuite library is required. You do not need to change your test classes.
The following tasks require only initial effort in SCTM:
When you use the test package feature, an SCTM test exists for each JUnit test class and method that is being executed. Additionally, each run of the JUnit suite automatically adds the corresponding SCTM tests, each time a test class or test method is added.
For more information refer to the ClasspathSuite documentation and to the SilkCentral Test Manager Help (JUnit test type).
package com.borland.testtests;
import org.junit.extensions.cpsuite.ClasspathSuite;
import org.junit.extensions.cpsuite.ClasspathSuite.ClasspathProperty;
import org.junit.extensions.cpsuite.ClasspathSuite.IncludeJars;
import org.junit.runner.RunWith;
@RunWith(ClasspathSuite.class)
@ClasspathProperty("classpathsuite.path")
@IncludeJars(true)
public class AllTestsSuite {
//Execute all classes containing methods with @Test annotation from path defined in SCTM parameter "classpathsuite.path"
}
Define the fully qualified class name of the entry point class for the Test class property. In the Classpath property, you can use SCTM parameter replacement, so that you have to define the path where test classes reside in only one place as a custom parameter.
Libraries and code that shall be tested do not need to be included in a search for test classes. So, these are stored in a separate location, which in our example is C:\TestsHome\lib\*.
Alternatively, you can restrict which classes should be executed by using the @ClassnameFilters annotation in the suite class, or by using multiple suite classes with different filters.
Because SCTM sets any custom parameter as Java system property, you can use the parameter name in the entry point class to restrict the path to search for test classes:
Assign the added test to an execution plan and start it. When the run is finished and the results are stored, the run results include a file named "output.xml". This file contains information about the hierarchy structure of all JUnit classes and methods that have been executed.
Next, in the Tests area, right-click the test and click Convert to Test Package. This will read the information from the output.xml file of the latest run and will create the corresponding test-hierarchy structure, so that there is an SCTM test for each test method that has been executed in the run. The generated test names correspond to the Java class names and the method names. Once the test is a Test Package, this transformation of execution results to a corresponding test-hierarchy structure is done by SCTM after each test run.