Zero Maintenance JUnit Testing using ClasspathSuite in SCTM

Zero Maintenance JUnit Testing using ClasspathSuite in SCTM

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).

Create a JUnit Suite Class as Entry Point for SCTM

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.

Define the Entry Point Class in SCTM

The following tasks require only initial effort in SCTM:

  • Adding a test and specifying the classpath and the JUnit Suite class.
  • Running the test.
  • Converting the test to a test package with the Convert to Test Package action.

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).

 

Example

 

JUnit Suite Class As Entry Point Denoted in Test Manager

 

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"
}

 

Adding a JUnit Test in SCTM

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.

  

 

Adding a Custom Parameter

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:

 

 

Running the Test and Converting it to a Test Package

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.

 

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Comments

I tried to do this but no luck.. The "AllTestSuite" file works fine in eclipse but then I get a ClassNotFoundException. I just want to verify that with this method I do not need a jar file, is that correct?

Hello vb22,

If you are using Silk Central version 15 or 15.5, you do not need the workaround with this 3rd party library. We have added similar functionality to Silk Central.

(we will change this WIKI page accordingly)

From the current documentation:

"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. "

regards

-max

Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2012-06-21 16:58
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.