I am using testNG for writing test cases, all testcase code is inside src/test/java folder, now i want to run testcases inside this folder from a class inside src/main/java after deployment of the application,will it be possible?
file under src/main/java-> TestNGRun
public class TestNGRun {
public static void runTestNg() {
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testNG = new TestNG();
testNG.addListener(tla);
List<String> suites = new ArrayList<String>();
URL filePathUrl = TestNGRun.class.getClassLoader().getResource("/testng.xml");
suites.add(filePathUrl.getPath());
testNG.setTestSuites(suites);
testNG.run();
}
}
file under src/main/resources--> testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
<listeners>
<listener
class-name="com.cypress.prodService.testNG.CustomisedReports"></listener>
</listeners>
<test name="ProductServiceImplTest">
<classes>
<class
name="com.cypress.prodService.testNG.ProductServiceImplTest"></class>
</classes>
</test>
</suite>
file under src/test/java --> ProductServiceImplTest.java
@Test
public class ProductServiceImplTest {
@Test
public void addProduct() {`enter code here`
String value="GoodMorning";
assertEquals("Hello", value);
}
}