gradle, testng project in leanft in Java

To create a LeanFT project with Gradle and TestNG, follow below steps. First of all, create a sample Gradle project in IntelliJ IDEA. Then add a libs directory under root directory and copy all LeanFT library files from C:\Program Files (x86)\HP\LeanFT\SDK\Java in it. Then ensure that your build.gradle file contains below configuration.
 
group 'org.softpost'
version '1.0-SNAPSHOT'

apply plugin: 'java'

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'org.testng', name: 'testng', version: '6.9.10'
    compile fileTree(dir: 'libs', include: '*.jar')
}

test {
    useTestNG {
        suites 'src/test/resources/testng.xml'
    }
}


After this, create a sample TestNG test class and add LeanFT test as shown in below example. Notice that you will have to initialize the LeanFT SDK before starting the tests and clean up SDK at the end of tests. After this build your project and then run the tests.
 
package org.softpost;

import com.hp.lft.report.Reporter;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.hp.lft.sdk.*;
import com.hp.lft.verifications.*;

import java.net.URI;


public class SimpleLeanFTTest {

    @BeforeClass
    public void beforeClass() {
    }

    @AfterClass
    public void afterClass() {
    }

    @BeforeMethod
    public void beforeMethod() {
        try {
            ModifiableSDKConfiguration config = new ModifiableSDKConfiguration();
            config.setServerAddress(new URI("ws://localhost:5095"));
            SDK.init(config);
            Reporter.init();
        }catch (Exception ex){
            System.out.println("Exception occured " + ex.toString());
        }
    }

    @AfterMethod
    public void afterMethod() throws Exception {
        Reporter.generateReport();
        SDK.cleanup();
    }

    @Test
    public void test() throws GeneralLeanFtException {
        Verify.areEqual(22,22,"Verify that 22 == 22");
    }

}

Complex problems, Simple Solutions