Code Sample :
Test1 class would be a parent class which would be responsible to execute Test2 class method
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method;
import org.testng.annotations.Test;
public class Test1 {
@Test
public void test() {
Class test2 = Test2.class;
Method method = null;
Object obj = null;
try {
method = test2.getMethod("test", String.class);
} catch (NoSuchMethodException | SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
method.setAccessible(true);
try {
obj = method.invoke(test2.newInstance(), "0");
} catch (IllegalAccessException | IllegalArgumentException
| InvocationTargetException | InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Test2.class code :
import org.testng.Assert;
public class Test2 {
public void test(String obj){
Assert.assertEquals(obj, "1");
}
} Here as per this example , assertion should fail , but testng report states as passed So how do i link assertion failure to the testng report