junit4 icon indicating copy to clipboard operation
junit4 copied to clipboard

Inheritance of Categories

Open gaffa opened this issue 14 years ago • 7 comments

I need to Annotate all our IntegrationTests. As I realized they all inherit from only like 3 different abstract tests I felt like maybe I am ready already because I simply can annotate the abstract class. Just that this behaviour is not as expected.

Example:

@Category(IT.class) public class A{ @Test public void testInAnnotatedClass() { System.out.println("inheritance: method in annotated class ran."); } }

public class B extends A{ @Test public void testInInheritingClass() { System.out.println("inheritance: method in inheriting class ran."); } }

Running this will result in only testInAnnotatedClass() being ran.

gaffa avatar Nov 29 '12 09:11 gaffa

If the Category annotation was annotated by java.lang.annotation.Inherited, then the test B would be category as well.

Tibor17 avatar Nov 29 '12 11:11 Tibor17

I have cloned your repo and implemented the functionality with an optional Parameter "inherited" in Category that defaults to false. I further changed the Categories-Runner to evaluate this Parameter and support inheritance. This does not change the current behaviour but supports optional inheritance. Im just too dumb to understand how to ask you to merge it back :) Its only one commit containing a one-line-change to Category one Method in Categories and some Code changes in Categories. I also added a simple test demonstrating that no changes to default behaviour are made and that the optional inheritance works.

gaffa avatar Dec 03 '12 14:12 gaffa

@gaffa, there should be a "Pull Request" button at the top of your fork. That should get you on your way to creating an official pull request. Thanks!

dsaff avatar Dec 03 '12 16:12 dsaff

Perfect. Thank you!

gaffa avatar Dec 03 '12 17:12 gaffa

@other people interested in this: http://tech.groups.yahoo.com/group/junit/surveys?id=3125322

gaffa avatar Dec 03 '12 20:12 gaffa

It looks like this issue can be closed as it has been resolved by pull request #566

avandeursen avatar Jan 09 '13 20:01 avandeursen

Agreed.

dsaff avatar Jan 10 '13 18:01 dsaff