-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Consider below example:
Example uses following dependencies:
spring-test:5.3.3
spring-context:5.3.3
spring-core:5.3.3
testng:7.3.0
package com;
import com.SkipTest.SkipTestConfig;
import com.SkipTest.SkipTestListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.IInvokedMethod;
import org.testng.IInvokedMethodListener;
import org.testng.ITestResult;
import org.testng.SkipException;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
@ContextConfiguration(classes = SkipTestConfig.class)
@Listeners(SkipTestListener.class)
public class SkipTest extends AbstractTestNGSpringContextTests {
@Test
public void shouldNotBeExecuted() {
System.out.println("EXECUTED");
}
@Configuration
public static class SkipTestConfig {
}
public static class SkipTestListener implements IInvokedMethodListener {
@Override
public void beforeInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) {
throw new SkipException("skip");
}
@Override
public void afterInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) {
System.out.println(iTestResult.getStatus());
}
}
}When extends AbstractTestNGSpringContextTests is added then test fails because throwing SkipException in listener method is treated as any other exception.
When extends AbstractTestNGSpringContextTests is removed, then shouldNotBeExecuted is skipped as expected.
Use case:
My system level tests use TestNG listener mechanism to perform several actions, one of which is deciding if given system test can be executed. If test should not be executed then we mark it as skipped and throw SkipException.
This worked flawlessly for TestNG versions 6.+ for version 7.+ it does not, and the issue seems to be in AbstractTestNGSpringContextTests.