Если вы хотите пометить метод @Test
как пропущенный и по-прежнему не хотите видеть информацию об исключениях в отчетах, вам не следует выбрасывать TestSkipException
.
Вот как вы это делаете (вам нужно использовать слушателей TestNG)
Тестовый класс выглядит следующим образом
import org.testng.Reporter;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
@Listeners(SkipMarker.class)
public class SampleTestClass {
@Test
public void passMethod() {}
@Test
public void skipMethod() {
// Adding an attribute to the current Test Method's result object to signal to the
// TestNG listener (SkipMarker), that this method needs to be marked as skipped.
Reporter.getCurrentTestResult().setAttribute("shouldfail", true);
}
}
Вот как выглядит слушатель TestNG
import org.testng.IInvokedMethod;
import org.testng.IInvokedMethodListener;
import org.testng.ITestResult;
public class SkipMarker implements IInvokedMethodListener {
@Override
public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {}
@Override
public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
// Look for the signalling attribute from the test method's result object
Object value = testResult.getAttribute("shouldfail");
if (value == null) {
// If the attribute was not found, dont proceed further.
return;
}
// attribute was found. So override the test status to failure.
testResult.setStatus(ITestResult.FAILURE);
}
}