Create tests in ALM

This topic includes information on creating a test that can be run from ALM. You can use the Retrieve ALM information in your tests to retrieve information on ALM that is important to you. Aside from creating the tests in OpenText Functional Testing for Developers, you also need to create parallel tests in ALM, as described in Create tests in ALM.

Set up your testing project

  1. In OpenText Functional Testing for Developers, create a project containing one or more test methods. For details, see Create a testing project or module.

    • These test methods can be defined in a single .cs or .java file, or in multiple files within your project.
    • Use Retrieve ALM information in your test script.
  2. Compile the DLL or create the JAR.

Retrieve ALM information

OpenText Functional Testing for Developers includes a set of comprehensive API methods for retrieving information on your ALM environment, such as the ALM project name or the ALM server domain name. This capability is supported for all ALM testing frameworks (JUnit, NUnit, and TestNG).

You can retrieve information for both test runs and business components runs.

Retrieve ALM information using the getAlmRunInfo method in the ALMUtils class.

Example:  

AlmRunInfo runInfo = AlmUtils.getAlmRunInfo();

The getAlmRunInfo method returns an AlmRunInfo class when the test is run from ALM. If the test is not run from ALM, it returns NULL.

Retrieve business component information using the getBusinessComponentRunInfo method in the AlmRunInfo class.

Example:  

AlmRunInfo almRunInfo = AlmUtils.getAlmRunInfo();
if (almRunInfo != null) {
	BusinessComponentRunInfo bcRunInfo = almRunInfo.getBusinessComponentRunInfo();
}		

The getBusinessComponentRunInfo method returns a bcRunInfo class when the test is run from ALM. If the test is not run from ALM, it returns NULL.

For details on all the properties you can retrieve, see the .NET and the Java SDKs.

For full code examples, see Code examples.

Create tests in ALM

Each test method in your testing project that you want to run in ALM must be mapped to an ALM LEANFT-TEST test.

You can create a LEANFT-TEST test manually for each test method, or you can use the import tool to create multiple tests simultaneously. Importing is recommended if you want to migrate a large number of test methods to ALM.

Manually create LEANFT-TEST tests in ALM

Create a LEANFT-TEST test in ALM for each test method in your OpenText Functional Testing for Developers test script.

  1. In the ALM Test Plan module, create a test, and select the LEANFT-TEST test type.

  2. In the test plan tree, select the LEANFT-TEST test you just created.
  3. In the Test Script tab of the test, define your test. Provide values for required fields, as follows:

    Field Description

    Framework

    Select the framework you are using.

    JAR/DLL Path

    The path of the .jar or .dll file containing your test.

    Specify either a full file path or a path relative to that specified in the <TestAssetsDir> element of the LFTRemoteAgent.exe.config file.

    Fully Qualified Class Name

    The fully qualified name of your class, including the namespace (NUnit/MSTest) or package (JUnit/TestNG).

    Syntax: <package/namespace name>.<classname>

    Test Method Name

    The name of the test method that your ALM test will run.

    • For a Cucumber project, use #all_methods#.
    • You can also use the #all_methods# keyword for JUnit tests, to instruct ALM to run all the methods in the test class.

    Example:  

    Repeat for each test method that you want to include in your ALM test plan.

Import tests into ALM

Use the OpenText Functional Testing for Developers Test Export tool to export your test methods.

Then, on the ALM side, use the OpenText Functional Testing for Developers Test Import tool to import the test methods into ALM LEANFT-TEST tests.

  1. From the command line, run the export tool relevant to your testing framework. These are located in the <Installdir>\Tools\TestExportTool folder. For details, see Exporting test methods

    The export tool generates an XML file with the same name and in the same location as the DLL or JAR you provided.

    Example: C:\UFT Developer\MyJUnitTests.xml.

  2. In ALM, in the Test Plan module, run the ALM import tool:

    1. Select Tests > Import OpenText Functional Testing for Developers Tests.

    2. Select the XML file generated with the export tool in OpenText Functional Testing for Developers and click Open.
    3. Select the test methods to import and click Import.

      Example:  

      A LEANFT-TEST test is created for each selected test method, with all required fields defined.

Back to top

Exporting test methods

Use the OpenText Functional Testing for Developers Test Export tool to export your test methods. Then, import the tests into ALM. For details, see Import tests into ALM.

From the command line, run the export tool relevant to your testing framework. These are located in the <Installdir>\Tools\TestExportTool folder. You can export NUnit, MSTest, TestNG, or JUnit.

NUnit/MSTest

Run LFTTestExportTool.exe, providing the path of your test project DLL.

Note: The export tool uses NUnit as the default framework so you do not need to specify the framework.

However, for MSTest, make sure to specify the framework as well, as demonstrated in the example below.

Example for NUnit:

"C:\Program Files (x86)\OpenText\UFT Developer\Tools\TestExportTool\LFTTestExportTool.exe" "C:\UFT Developer\MyNUnitTests.dll"

Example for MSTest:

"C:\Program Files (x86)\OpenText\UFT Developer\Tools\TestExportTool\LFTTestExportTool.exe" "C:\UFT Developer\MyMSTestTests.dll" -framework:MSTest

TestNG

Run test-export-tool.jar, providing the path to your test project .jar and your testng.jar.

Tip: To simplify, use the %CLASSPATH% environment variable to set the testng.jar paths.

Use the following syntax:

java -jar <export tool jar><OpenText Functional Testing for Developers project jar path>-classpath:<testng.jar path>‑framework:TestNG

or

java -cp "<export tool folder>/*;<testng.jar path>" com.hp.lft.testexporttool.ExportTests<OpenText Functional Testing for Developers project jar path>‑framework:TestNG

Note: The export tool uses JUnit as the default framework. Therefore, be sure to specify the TestNG framework in the command.

Examples

  • Using -jar:

    java -jar "C:\Program Files (x86)\OpenText\UFT Developer\Tools\TestExportTool\test-export-tool.jar" "C:\UFT Developer\MyTestNGTests.jar" -classpath:"C:\TestNG\testng.jar" ‑framework:TestNG

  • Using -cp

    java -cp "C:\Program Files (x86)\OpenText\UFT Developer\Tools\TestExportTool/*;C:\TestNG\testng.jar;" com.hp.lft.testexporttool.ExportTests "C:\UFT Developer\MyTestNGTests.jar" ‑framework:TestNG

JUnit 4

Run test-export-tool.jar, providing the path to your test project .jar and your junit.jar.

Use the following syntax:

java -jar <export tool jar><OpenText Functional Testing for Developers project jar path>-classpath:<junit.jar path>

or

java -cp "<export tool folder>/*;<junit.jar path>" com.hp.lft.testexporttool.ExportTests<OpenText Functional Testing for Developers project jar path>

Example

  • Using -jar:

    java -jar "C:\Program Files (x86)\OpenText\UFT Developer\Tools\TestExportTool\test-export-tool.jar" "C:\UFT Developer\MyJUnitTests.jar" -classpath:"C:\JUnit\junit.jar"

  • Using -cp:

    java -cp "C:\Program Files (x86)\OpenText\UFT Developer\Tools\TestExportTool/*;C:\JUnit\junit.jar;" com.hp.lft.testexporttool.ExportTests "C:\UFT Developer\MyJUnitTests.jar"

Hamcrest JAR

Some versions of JUnit require adding the Hamcrest JAR path to the classpath argument of the export tool command line. If yours does, use the following syntax, using a semi-colon delimited list for the classpath:

Tip: To simplify, use the %CLASSPATH% environment variable to set the junit and hamcrest jar paths.

java -jar <export tool jar> <OpenText Functional Testing for Developers project jar path> -classpath:"<junit.jar path>;<hamcrest-core.jar path>"

or

java -cp "<export tool folder>/*;<junit.jar path>;<hamcrest-core.jar path>" com.hp.lft.testexporttool.ExportTests<OpenText Functional Testing for Developers project jar path>

Examples:

  • Using -jar:

    java -jar "C:\Program Files (x86)\OpenText\UFT Developer\Tools\TestExportTool\test-export-tool.jar" "C:\UFT Developer\MyJUnitTests.jar" -classpath:"C:\JUnit\junit.jar;C:\JUnit\hamcrest-core.jar"

  • Using -cp:

    java -cp "C:\Program Files (x86)\OpenText\UFT Developer\Tools\TestExportTool/*;C:\JUnit\junit.jar;C:\JUnit\hamcrest-core.jar" com.hp.lft.testexporttool.ExportTests "C:\UFT Developer\MyJUnitTests.jar"

Code examples

The following are full .NET and Java code examples for creating a test using the ALM APIs.

.NET examples

ALM test

[Test]
public void AlmUtilsAlmTestExample()
{
	// This test checks if the test is running from ALM, and if it is, 
       // it writes to the OpenText Functional Testing for Developers report the properties that AlmUtils support.
       var almRunInfo = AlmUtils.AlmRunInfo;
	if (almRunInfo == null)
	{
	// AlmUtils.AlmRunInfo property is null, the test is not running from ALM
        return;
	}
            
	// Write all the ALMUtils properties to a string to show it in the report
       var stringToReport = String.Format("ALMUtils test info properties: <BR>" +
				"ServerUrl: '{0}', <BR>" +
				"TesterName: '{1}', <BR>" +
				"TestId: '{2}', <BR>" +
				"TestName: '{3}', <BR>" +
				"TestSetId: '{4}', <BR>" +
				"TestSetName: '{5}', <BR>" +
				"RunId: '{6}', <BR>" +
				"RunName: '{7}', <BR>" +
				"DomainName: '{8}', <BR>" +
				"ProjectName: '{9}', <BR>" +
				"TestInstanceId: '{10}', <BR>",
				almRunInfo.ServerUrl,
				almRunInfo.TesterName,
				almRunInfo.TestId,
				almRunInfo.TestName,
				almRunInfo.TestSetId,
				almRunInfo.TestSetName,
				almRunInfo.RunId,
				almRunInfo.RunName,
				almRunInfo.DomainName,
				almRunInfo.ProjectName,
				almRunInfo.TestInstanceId);
	Reporter.ReportEvent("AlmUtils.AlmRunInfo Properties Check", stringToReport, Status.Passed);

	IDictionary<string, object> testParams = almRunInfo.Parameters;
	if (testParams == null)
	{
		Reporter.ReportEvent("AlmUtils.AlmRunInfo Parameters Check", "No parameters in the test", Status.Passed);
	}
	else
	{
		var keys = testParams.Keys;
		string paramsString = null;
		foreach (var key in keys)
			{
			if (!String.IsNullOrEmpty(paramsString))
			{
				paramsString = paramsString + ",<br>";
			}
			paramsString = paramsString + "Parameter name: '" + key + "', parameter value: '" + testParams[key] + "'";
			}
		Reporter.ReportEvent("AlmUtils.AlmRunInfo Parameters Check", paramsString, Status.Passed);
	}
}		

ALM business components

[Test]
public void AlmUtilsAlmBusinessConponentExample()
{
// This test checks if the test is a business component running from ALM, and if it is, // it writes to the OpenText Functional Testing for Developers report the properties that AlmUtils support.var almRunInfo = AlmUtils.AlmRunInfo;
	if (almRunInfo == null)
	{
		// AlmUtils.AlmRunInfo property is null, the test is not running from ALMreturn;
	}
	var businessComponentInfo = almRunInfo.BusinessComponentRunInfo;
	if (businessComponentInfo == null)
	{
		// AlmUtils AlmRunInfo's BusinessComponentRunInfo property is null, this is not a business componentreturn;
	}

	var stringToReport = String.Format("AlmUtils business component info properties: <BR>" +
				"ServerUrl: '{0}', <BR>" +
				"TesterName: '{1}', <BR>" +
				"TestId: '{2}', <BR>" +
				"TestName: '{3}', <BR>" +
				"TestSetId: '{4}', <BR>" +
				"TestSetName: '{5}', <BR>" +
				"RunId: '{6}', <BR>" +
				"RunName: '{7}', <BR>" +
				"DomainName: '{8}', <BR>" +
				"ProjectName: '{9}', <BR>" +
				"TestInstanceId: '{10}', <BR>" +
				"ComponentId: '{11}'<BR>" +
				"ComponentName: '{12}'<BR>" +
				"Iteration: '{13}'<BR>" +
				"TotalNumberOfIterations: '{14} <BR>",
				almRunInfo.ServerUrl,
				almRunInfo.TesterName,
				almRunInfo.TestId,
				almRunInfo.TestName,
				almRunInfo.TestSetId,
				almRunInfo.TestSetName,
				almRunInfo.RunId,
				almRunInfo.RunName,
				almRunInfo.DomainName,
				almRunInfo.ProjectName,
				almRunInfo.TestInstanceId,
				businessComponentInfo.ComponentId,
				businessComponentInfo.ComponentName,
				businessComponentInfo.Iteration,
				businessComponentInfo.TotalNumberOfIterations);
	Reporter.ReportEvent("AlmUtils.BusinessComponentRunInfo Properties Check", stringToReport, Status.Passed);

	IDictionary<string, object> testParams = almRunInfo.Parameters;
	if (testParams == null)
		{
		Reporter.ReportEvent("AlmUtils BusinessComponentRunInfo Parameters Check", "No parameters in the test", Status.Passed);
		}
	else
	{
		var keys = testParams.Keys;
		string paramsString = null;
		foreach (var key in keys)
		{
			if (!String.IsNullOrEmpty(paramsString))
			{
				paramsString = paramsString + ",<br>";
			}
			paramsString = paramsString + "Parameter name: '" + key + "', parameter value: '" + testParams[key] + "'";
		}
		Reporter.ReportEvent("AlmUtils BusinessComponentRunInfo Parameters Check", paramsString, Status.Passed);
	}
}		

Java examples

ALM test

@Test
public void testAlmUtilsExample() throws GeneralLeanFtException, ReportException, IOException {
// This test checks if the test is running from ALM, and if it is, 
// it writes to the OpenText Functional Testing for Developers report all the properties that AlmUtils support.
	AlmRunInfo almRunInfo = AlmUtils.getAlmRunInfo();
	if (almRunInfo == null){
	// AlmUtils.getAlmRunInfo() returned null, the test is not running from ALMreturn;
	}
    	
	// Create a string builder, and add the properties of the test running
	StringBuilder sb = new StringBuilder();
	sb.append("ALMUtils test info properties: <BR>");
	sb.append(String.format("ServerUrl: '%s' <BR>", almRunInfo.getServerUrl()));
	sb.append(String.format("TesterName: '%s' <BR>", almRunInfo.getTesterName()));
	sb.append(String.format("TestId: '%d' <BR>", almRunInfo.getTestId()));
	sb.append(String.format("TestName: '%s' <BR>", almRunInfo.getTestName()));
	sb.append(String.format("TestSetId: '%d' <BR>", almRunInfo.getTestSetId()));
	sb.append(String.format("TestSetName: '%s' <BR>", almRunInfo.getTestSetName()));
	sb.append(String.format("RunId: '%d' <BR>", almRunInfo.getRunId()));
	sb.append(String.format("RunName: '%s' <BR>", almRunInfo.getRunName()));
	sb.append(String.format("TestInstanceId: '%d' <BR>", almRunInfo.getTestInstanceId()));
	String stringToReport = sb.toString();
	Reporter.reportEvent("AlmUtils.getAlmRunInfo() Properties Check", stringToReport);
    	
	Map<String, Object> testParams = almRunInfo.getParameters();
	if (testParams == null){
		Reporter.reportEvent("AlmUtils.getAlmRunInfo() Parameters Check", "No parameters in the test");
	}
	else{
		String paramString = "";
		for (Map.Entry<String, Object> testParam: testParams.entrySet()){
			paramString += String.format("Parameter name: '%s', parameter value: '%s' <BR>", testParam.getKey(), testParam.getValue().toString());
		}
		Reporter.reportEvent("ALMUtils.getAlmRunInfo Parameters Check", paramString);
	}
}		

ALM business components

@Test
	public void testAlmUtilsBcExample() throws GeneralLeanFtException, ReportException, IOException {
// This test checks if the test is a business component running from ALM, and if it is, // it writes to the OpenText Functional Testing for Developers report all the properties that AlmUtils support.
	AlmRunInfo almRunInfo = AlmUtils.getAlmRunInfo();
	if (almRunInfo == null){
	// AlmUtils.getAlmRunInfo() returned null, the test is not running from ALMreturn;
	}
	BusinessComponentRunInfo bcRunInfo = almRunInfo.getBusinessComponentRunInfo();
	if (bcRunInfo == null){
	// AlmUtils.getBusinessComponentRunInfo() returned null, the test is not a business componentreturn;
	}
    	
	// Create a string builder, and add the properties of the test running
	StringBuilder sb = new StringBuilder();
	sb.append("ALMUtils test info properties: <BR>");
	sb.append(String.format("ServerUrl: '%s' <BR>", almRunInfo.getServerUrl()));
	sb.append(String.format("TesterName: '%s' <BR>", almRunInfo.getTesterName()));
	sb.append(String.format("TestId: '%d' <BR>", almRunInfo.getTestId()));
	sb.append(String.format("TestName: '%s' <BR>", almRunInfo.getTestName()));
	sb.append(String.format("TestSetId: '%d' <BR>", almRunInfo.getTestSetId()));
	sb.append(String.format("TestSetName: '%s' <BR>", almRunInfo.getTestSetName()));
	sb.append(String.format("RunId: '%d' <BR>", almRunInfo.getRunId()));
	sb.append(String.format("RunName: '%s' <BR>", almRunInfo.getRunName()));
	sb.append(String.format("TestInstanceId: '%d' <BR>", almRunInfo.getTestInstanceId()));
	sb.append(String.format("ComponentId: '%d' <BR>", bcRunInfo.getComponentId()));
	sb.append(String.format("ComponentName: '%s' <BR>", bcRunInfo.getComponentName()));
	sb.append(String.format("Iteration: '%d' <BR>", bcRunInfo.getIteration()));
	sb.append(String.format("TotalNumberOfIterations: '%d' <BR>", bcRunInfo.getTotalNumberOfIterations()));
	String stringToReport = sb.toString();
	Reporter.reportEvent("AlmUtils.getAlmRunInfo() Properties Check", stringToReport);
    	
	Map<String, Object> testParams = almRunInfo.getParameters();
	if (testParams == null){
		Reporter.reportEvent("AlmUtils.getAlmRunInfo() Parameters Check", "No parameters in the test");
	}
		else{
			String paramString = "";
			for (Map.Entry<String, Object> testParam: testParams.entrySet()){
				if (testParam.getValue()!=null){
				paramString += String.format("Parameter name: '%s', parameter value: '%s' <BR>", testParam.getKey(), testParam.getValue().toString());
				}
				else {
				paramString += String.format("Parameter name: '%s', parameter value: '%s' <BR>", testParam.getKey(), "");    			
				}
			}
		Reporter.reportEvent("ALMUtils.getAlmRunInfo Parameters Check", paramString);
	}
}		

Back to top

Next steps: