Skip to content

Junit | Can we add @Inherited to org.junit.experimental.categories.Category annotation #398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
muralidh opened this issue Mar 16, 2012 · 9 comments

Comments

@muralidh
Copy link

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

@Tibor17
Copy link
Contributor

Tibor17 commented Mar 18, 2012

What would be then the backwards compatibility when super class has category?
IMHO junit test classes inheritance is useless.

@inherited
Copy link

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

@muralidh
Copy link
Author

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

@Tibor17
Copy link
Contributor

Tibor17 commented Mar 18, 2012

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.

@muralidh
Copy link
Author

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

@Tibor17
Copy link
Contributor

Tibor17 commented Mar 19, 2012

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.

@mmichaelis
Copy link
Contributor

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.

@marcphilipp
Copy link
Member

Fixed by #566, will be released in 4.12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants