I started using TestNG just a few months ago. I want to skip a @Test that has a bug associated waiting to be fixed, without ignoring it (that is, without marking it as enabled=false) as I still want it to appear in the report as a skipped.
I also have dependencies to that test, so if I just ignore the @Test, then I will have to change all the dependencies. I prefer skipping the test, so the depending tests would just be skipped as well.
I'm currently trying to do:
@Test(enabled = true, groups = { "GroupA" }, dependsOnMethods = { "MethodB" } )
public void testA() {
throw new SkipException("Test blocked due to Bug-1234");
doTest(); // Compile error: Unreachable code.
}
A quick solution would be to comment that code, but that would generate a lot of warnings, and wouldn't look good.
I could also add an if(true) before the Skip, as I saw in other solutions, but that generates a dead code warning that I would prefer to avoid.
Rather than "what can I do?", my question would be "what would you do?". Is there a common practice to deal with this with TestNG?
(This is my very first post, please forgive me if I failed to find an already existing answer to this).
After trying different things with Listeners and some other ways, I came to the conclusion that the best thing I could do, as far as I know, was just to add a static method that would be defined in a super class or a utility package:
@Test( enabled = true,
description = "Validates that it is possible to create a new booking.")
public void validateCreateNewBooking() {
skipTest("BUG-1234");
doTest();
}
Where skipTest:
public static void skipTest(String reason) {
throw new SkipException("Test voluntarily skipped. Reason: " + reason);
}
So result:
SKIPPED: validateCreateNewBooking
Validates that it is possible to create a new booking.
org.testng.SkipException: Test voluntarily skipped. Reason: BUG-1234
at com.openjaw.testregression.tretailapi.test.TestConfig.skipTest(TestConfig.java:28)
at com.openjaw.testregression.tretailapi.test.booking.CreateBookingTest.validateCreateNewBooking(CreateBookingTest.java:16)