Junit | Can we add @Inherited to org.junit.experimental.categories.Category annotation
Hi,
We use junit 4.10 along with maven-surefire-plugin. For running all integration tests that belong to a particular category. without @Inherited annotation in org.junit.experimental.categories.Category, maven-surefire-plugin requires each test case to be annotated individually.
It would be great to have the support of running all test cases that extend the parent class which has a specified category annotation , instead of requiring each test class to have that category annotation.
I agree that changes can be made at surefire-plugin side to explicitly look for the annotation in the parent class, submitted a patch to surefire-plugin for the same: https://jira.codehaus.org/browse/SUREFIRE-829 , but things will be cleaner if @Inherited is added to Category class in junit itself.
What are the disadvantages of this approach ? (If Category annotation is used only for grouping tests, this would be a good approach. Wouldnt it? )
Can you please let me know which one is better ?
Thanks, Gayathri
What would be then the backwards compatibility when super class has category? IMHO junit test classes inheritance is useless.
I definitely chose the wrong nick name for github :)
(please ignore this message and go on, but have in mind that adding
"@inherited" to your messages results in github sending me a copy of your
message)
Greetings inherited
Am 18.03.2012, 17:11 Uhr, schrieb Tibor17
[email protected]:
what would be then the backwards compatibility when super class has
category?
Reply to this email directly or view it on GitHub: https://github.com/KentBeck/junit/issues/398#issuecomment-4562189
Thanks for the reply Tibor.
What about allowing subclasses to override the superclass category ? But here again, the surefire-plugin code needs to be changed to honor the new behavior, if at all its modified.
Thanks, Gayathri
-----Original Message----- From: Tibor17 [mailto:[email protected]] Sent: Sunday, March 18, 2012 9:42 PM To: Muralidharan, Gayathri Subject: Re: [junit] Junit | Can we add @Inherited to org.junit.experimental.categories.Category annotation (#398)
what would be then the backwards compatibility when super class has category?
Reply to this email directly or view it on GitHub: https://github.com/KentBeck/junit/issues/398#issuecomment-4562189
What if someone already uses class inheritance and the nowadays Category annotation on methods and very super type -except for the rest of sub types. Once the class has Category, then the class' methods have it as well. After making the Category inherited, these people may start to claim of suddenly changed behavior of their tests in new JUnit version. Am i right? May this happen? There is no flag and no way to switch on/off this annotation inheritance in runtime.
Agreed. The behavior will change.
-----Original Message----- From: Tibor17 [mailto:[email protected]] Sent: Monday, March 19, 2012 2:07 AM To: Muralidharan, Gayathri Subject: Re: [junit] Junit | Can we add @Inherited to org.junit.experimental.categories.Category annotation (#398)
What if someone already uses class inheritance and the nowadays Category annotation on methods and very super type -except for the rest of sub types. Once the class has Category, then the class' methods have it as well. After making the Category inherited, these people may start to claim of suddenly changed behavior of their tests in new JUnit version. Am i right? May this happen? There is no flag and no way to switch on/off this annotation inheritance in runtime.
Reply to this email directly or view it on GitHub: https://github.com/KentBeck/junit/issues/398#issuecomment-4564218
Nevertheless the junit core might be able to accomplish the inheritance in other way, but you have to find out some concept via junit annotations and get an agreement in the community.
I also have an issue with not having @Category to be inherited by subclasses. But I agree that it's bad to introduce this now as it will break existing behavior (although you might say that categories are still experimental and thus breaking changes are "allowed").
But what does someone expect if a base class for the tests is annotated with @Category. For example @Category(IntegrationTest.class)? I assume that everyone would expect that all subclasses are now also taken as integration tests.
See: https://github.com/KentBeck/junit/issues/558 https://github.com/KentBeck/junit/pull/563 Vote: http://tech.groups.yahoo.com/group/junit/surveys?id=3125322
Fixed by #566, will be released in 4.12.