# Create LeanFT tests in ALM

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

In this topic:

## Set up your LeanFT project

1. In LeanFT, create a LeanFT project containing one or more test methods. For details, see Create a LeanFT 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 LeanFT ALM APIs in your test script.
2. Compile the DLL or create the JAR.

## LeanFT ALM APIs

LeanFT includes a set of comprehensive 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 regular 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 LeanFT tests in ALM

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

This can be done in one of the following ways:

Manually create LEANFT-TEST tests in ALM | Create a LEANFT-TEST test in ALM for each test method in your LeanFT test script.
Import LeanFT tests into ALM | Use the import tool to create LEANFT-TEST test for multiple test methods simultaneously. Recommended if you want to migrate a large number of test methods to ALM.

Manually create LEANFT-TEST tests in ALM

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:

   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 LeanFT test method that your ALM test will run. LeanFT 14.53 or later: For a Cucumber project, use `#all_methods#`. You can also use the `#all_methods#` keyword for other test types, 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 LeanFT tests into ALM

Use the LeanFT Test Export tool to export your test methods. Then, on the ALM side, use the LeanFT 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 <LeanFT installation>\Tools\TestExportTool folder.

   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)\Micro Focus\LeanFT\Tools\TestExportTool\LFTTestExportTool.exe "C:\LeanFT\MyNUnitTests.dll"`

   Example for MSTest:

   `C:\Program Files (x86)\Micro Focus\LeanFT\Tools\TestExportTool\LFTTestExportTool.exe "C:\LeanFT\MyMSTestTests.dll" -framework:MSTest`

   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><LeanFT project jar path> -classpath:<junit.jar path>`

   or

   `java -cp "<export tool folder>/*;<junit.jar path>" com.hp.lft.testexporttool.ExportTests <LeanFT project jar path>`

   Example

   - Using -jar:

     `java -jar "C:\Program Files (x86)\Micro Focus\LeanFT\Tools\TestExportTool\test-export-tool.jar" "C:\LeanFT\MyJUnitTests.jar" -classpath:"C:\JUnit\junit.jar"`

   - Using -cp:

     `java -cp "C:\Program Files (x86)\Micro Focus\LeanFT\Tools\TestExportTool/*;C:\JUnit\junit.jar;" com.hp.lft.testexporttool.ExportTests "C:\LeanFT\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> <LeanFT 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<LeanFT project jar path>`

   Examples:

   - Using -jar:

     `java -jar "C:\Program Files (x86)\Micro Focus\LeanFT\Tools\TestExportTool\test-export-tool.jar" "C:\LeanFT\MyJUnitTests.jar" -classpath:"C:\JUnit\junit.jar;C:\JUnit\hamcrest-core.jar"`

   - Using -cp:

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

   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><LeanFT project jar path>-classpath:<testng.jar path>‑framework:TestNG`

   or

   `java -cp "<export tool folder>/*;<testng.jar path>" com.hp.lft.testexporttool.ExportTests<LeanFT 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)\Micro Focus\LeanFT\Tools\TestExportTool\test-export-tool.jar" "C:\LeanFT\MyTestNGTests.jar" -classpath:"C:\TestNG\testng.jar" ‑framework:TestNG`

   - Using -cp

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

   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:\LeanFT\MyJUnitTests.xml.

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

   1. Select Tests > Import LeanFT Tests.

   2. Select the XML file generated with the export tool in LeanFT 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

## Code examples

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

.NET examples

Regular ALM test

    [Test]
    public void AlmUtilsAlmTestExample()
    {
    	// This test checks if the test is running from ALM, and if it is,

           // it will write to the LeanFT 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 proeprties: <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 will write to the LeanFT 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 buseiness componentreturn;
    	}

    	var stringToReport = String.Format("AlmUtils business component info proeprties: <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

Regular ALM test

    @Test
    public void testAlmUtilsExample() throws GeneralLeanFtException, ReportException, IOException {
    	// This test check if the test is running from ALM, and if it is, // it will write to the LeanFT 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 proeprties: <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 check if the test is a business component running from ALM, and if it is, // it will write to the LeanFT 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 proeprties: <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:

- Configure the LeanFT host computer

https://admhelp.microfocus.com LeanFT 8942
Tips to improve your search results...TOC Lean Functional Testing Help Center LeanFT Help Center 14.50 - 14.53 All View Local Help Center View Online Help Center back Go back in browser history forward Go forward in browser history Remove search highlights next topic Go to next topic previous topic Go to previous topic Print the current topic Version:(Undefined variable: _rscC_Basic_Variables.FloatingTocShow)