There are some test classes which needs to be ignored when I run my testng suite. I tried using the @Test(enabled=false) annotation for the class and methods that needs to be ignored. But my problem is that the class that needs to be ignored extends an abstract class and this abstract class test methods are not ignored even when I have @Test(enabled=false) annotation on the base class. In Junit I could use @ignore on the base class and the test methods on the extended class would not be invoked at all. How can I replicate this behaviour in testng.
Also In my testng suite I run the test by packages and not by classes. Hence even if I try to group the class and ignore the group it is not working either.
<test name="Test">
<groups>
<run>
<exclude name="testClass"/>
</run>
</groups>
<packages>
Please help
In TestNG, @Test(enabled=false) annotation is used to skip a test case if it is not ready to test. We don't need to import any additional statements. And We can Skip a test by using TestNG Skip Exception if we want to Skip a particular Test.
Ignore means do not run it at all, and skip with the combinations of Listeners can be use for listening dependent methods and/or test. So let assume you have dependency between two tests and /or methods, test 2 can be performed only if test 1 pass. Skip will hapen for test 2 if test 1 fails.
TestNG provides @Ignore annotation that is used to ignore or skip the test executions. The @Ignore can be used in 4 places: In a test method.
I received a response from Cedric on this from the google groups(Testng) . I am pasting it below for reference
Hi Paul,
What you are seeing is an unfortunate consequence of the way inheritance of annotations and default attributes interact with each other in TestNG, and a bug has been filed to make it work better (I don't have the id handy).
Consider:
@Test(enabled = false)
public class C {
@Test
public void f()
}
When TestNG resolves these annotations, it finds that the @Test on the method doesn't specify "enabled", so it assigns it its default value. The example becomes:
@Test(enabled = false)
public class C {
@Test(enabled = true)
public void f()
}
And now, the value defined at the method level overrides the one specified on the class.
The fix would involve using an enum instead of a boolean (ENABLED, DISABLED, INHERITED, which would be the default), but this would break backward compatibility, so I would need to introduce a new annotation for this (e.g. "runStatus" or something like that), and your example would become
@Test(runStatus = DISABLED)
public class C {
@Test
public void f()
}
Does this make sense?
-- Cédric
As mentioned in response from Cedric, method level Test annotation overrides class level Test annotation. Hence, the test methods are enabled even in case you have @Test(enabled=false) at class level. I was facing the same problem. It got fixed with the following approach.
The simplest solution is to have @Test(enabled=false) at class level but remove @Test annotations from method level. Like this:
@Test(enabled = false)
public class C
{
public void f()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With