Hi Ashish,
I am doing practise of TestNG with the reference of your tutorial video. I have declared extentreports,extenttest and made utility function in TestBase Class. Then, I am using these objects and function in extending test calss but whemn I am running the testng.xml ,I wondered it is giving me null pointer exception. Below is my code:-
Test Base Class:-
package testbase;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.Status;
import extentreports.ExtentManager;
public class TestBase {
public ExtentReports rep;
public ExtentTest test;
public String testName=null;
@BeforeMethod
//public void init() {
public void init(ITestResult result) {
testName=result.getMethod().getMethodName().toUpperCase();
System.out.println(testName);
rep=ExtentManager.getReports();
//test=rep.createTest("Test A");
rep.createTest(testName);
}
@AfterMethod
public void quit() {
rep.flush();
}
public void log(String msg) {
test.log(Status.INFO, msg);
}
}
Test Class:-
@Test
public void testA() throws InterruptedException {
System.out.println("Starting A");
//test.log(Status.INFO, "Starting A");
log("Starting A");
Thread.sleep(3000);
System.out.println("Ending A");
//test.log(Status.INFO, "Ending A");
log("Ending A");
}
Testng.xml:-
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="My Test Suites">
<suite-files>
<suite-file path="suitea.xml"></suite-file>
<suite-file path="suiteb.xml"></suite-file>
<suite-file path="suitec.xml"></suite-file>
</suite-files>
</suite>
Hey buddy, looks like ExtentTest object is not created. Could you please post the complete exception track trace?