Reputation:
In TestNG, you disable tests by doing the following in the method:
@Test(enabled = false)
I was wondering if there was an automated way to scrub the entire suite in order to find all of the methods that have enabled set to false?
Upvotes: 1
Views: 508
Reputation: 1089
If you want to look at your entire code without using the transformer, you may try my dedicated library:
@Listeners(DisabledTestsListener.class)
public class InventoryTests {
@Test
@DisabledTestsCollector(testsPath = "/src/test/java")
void getDisabledTest() {
// This test would collect all disabled tests in TestNG project.
}
Output example:
Jul 14, 2018 11:57:28 AM com.github.automatedowl.tools.DisabledTestsListener afterInvocation
INFO: You have 2 disabled TestNG tests in your project.
Jul 14, 2018 11:57:28 AM com.github.automatedowl.tools.DisabledTestsListener afterInvocation
INFO: ---------------------------------------------
Jul 14, 2018 11:57:28 AM com.github.automatedowl.tools.DisabledTestsListener lambda$afterInvocation$0
INFO: firstDisabledTest is a TestNG test which currently disabled.
Jul 14, 2018 11:57:28 AM com.github.automatedowl.tools.DisabledTestsListener lambda$afterInvocation$0
INFO: ---------------------------------------------
Jul 14, 2018 11:57:28 AM com.github.automatedowl.tools.DisabledTestsListener lambda$afterInvocation$0
INFO: secondDisabledTest is a TestNG test which currently disabled.
Jul 14, 2018 11:57:28 AM com.github.automatedowl.tools.DisabledTestsListener lambda$afterInvocation$0
INFO: ---------------------------------------------
Upvotes: 0
Reputation: 5740
You can use an IAnnotationTransformer
:
public class MyTransformer implements IAnnotationTransformer {
public void transform(ITest annotation, Class testClass, Constructor testConstructor, Method testMethod) {
if (!annotation.getEnabled()) {
System.out.println(testClass != null ? testClass : testMethod);
}
}
}
Upvotes: 3