I'm using method level annotations, and I would like to disable all
the tests in a class, how can I do it? I've tried several things
without success, and I finally made a small test case to show my
problem:
1. Failing tests, either of the following options make my tests fail:
@Test
public class DisabledTest
{
public void fail( )
{
Assert.fail( );
}
}
public class DisabledTest
{
@Test
public void fail( )
{
Assert.fail( );
}
}
2. If i try to disable all the tests in the class at the class level,
they are still runned and fail as long as I maintain the method
annotations:
@Test(enabled = false)
public class DisabledTest
{
@Test
public void fail( )
{
Assert.fail( );
}
}
3. If I don't have method annotations, the tests are correctly
disabled:
@Test(enabled = false)
public class DisabledTest
{
public void fail( )
{
Assert.fail( );
}
}
So, is it possible to disable all the tests in a class without
modifying or deleting all the method annotations?
Thanks in advance, best regards
José González
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
What I find puzzling is that none of the method annotations explicitly
define "enabled = true", so I thought in this case the class level
annotation would win, as it's the only one explicitly defining
enabled. So I must understand that a Test annotation implicitly
defines "enabled = true" even if you don't specify it??
Thanks, best regards
José
On 11 mar, 18:01, Cédric Beust ♔ <cbe...@google.com> wrote:
> Correct: annotations defined on the class will be overridden by annotation
> defined on methods, this is intentional.
>
> The easiest way to solve your problem would be to implement an
> IAnnotationTransformer that would look up the @Test annotation, look up the
> class name and if it's the class you want to disable, add "enabled=false" to
> the @Test annotation.
>
> --
> Cedric
>
> 2010/3/11 José González Gómez <jose.gonzalez.go...@gmail.com>
> > testng-users...@googlegroups.com<testng-users%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/testng-users?hl=en.
>
> --
> ***Cédric
> *
Hi Cedric,
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
I've never programmed an annotation, so I didn't know about this...
After RTFM I've noticed you can't tell the difference between a
default value and an explicitly assigned value...
The only thing that comes to mind is to create a specific annotation
to enable / disable tests... that way you could disable a whole class
applying a @Disabled or @Enabled(false) annotation to the class. There
would be no problem about default values because you could check for
the presence of the annotation: a missing annotation would mean an
enabled test method, unless a class annotation is present.
I think this is far more flexible than the current approach: you could
have a completely disabled class and enable individual methods as the
method annotation would override the class annotation. What do you
think? Something worth creating a new feature ticket?
Thanks a lot, best regards
José
On 11 mar, 18:33, Cédric Beust ♔ <cbe...@google.com> wrote:
> Hi José,
>
> Correct, take a look at the definition of the @Test annotation:
>
> /**
> * Whether methods on this class/method are enabled.
> */
> public boolean enabled() default true;
>
> If I didn't specify a default, this attribute would no longer be optional,
> which is not acceptable.
>
> Because of this, when TestNG parses the value of this attribute, it has no
> way of knowing whether that value is the default or if it was specified by
> the user, so in both cases, it will override the value specified on the
> class annotation.
>
> I can't think of an easy way to work around this limitation right now...
>
> --
> ***Cédric
> *
> > <testng-users%2Bunsu...@googlegroups.com<testng-users%252Buns...@googlegroups.com>
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
Best regards
José
On 11 mar, 23:08, Cédric Beust ♔ <cbe...@google.com> wrote:
> No need for a feature ticket, you can implement this yourself :-)
>
> You could write an IMethodInterceptor which would check for the presence of
> a certain annotation on the class, such as @DisableTests, and if found,
> would return a list of all the methods that don't belong to that class.
>
> Doc: http://testng.org/javadocs/org/testng/IMethodInterceptor.html
>
> Let me know if you need help on how to implement this.
>
> --
> Cedric
>
> 2010/3/11 José González Gómez <jose.gonzalez.go...@gmail.com>
> > > > <testng-users%2Bunsu...@googlegroups.com<testng-users%252Buns...@googlegroups.com>
> > <testng-users%252Buns...@googlegroups.com<testng-users%25252Bun...@googlegroups.com>
> ***Cédric
> *
Ups, let me rephrase the question... do you think this is something
worth having in TestNG out of the box? I think it's a very useful
feature...
Well, I'm using the Eclipse Plugin, and I'm currently running all my
tests per project indicating the parent package where the tests are
located, so I don't use a testng.xml file... maybe I should use one?