junit4 icon indicating copy to clipboard operation
junit4 copied to clipboard

Multiple categories for @IncludeCategory and @ExcludeCategory

Open merland opened this issue 16 years ago • 12 comments

Hi list!

It would be great if @IncludeCategory and @ExcludeCategory would accept multiple categories like the @Category annotation does today.

There is a not-so-beatiful workaround. You can get multiple includes or excludes if you create an inheritance hierarchy of suites and exclude one category on each level.

merland avatar Oct 25 '10 13:10 merland

Yes, please!

nemoo avatar Jun 10 '11 12:06 nemoo

I couldn't get your suggested workaround to work. Could you provide more details?

ajmath avatar Oct 11 '11 14:10 ajmath

Ok, lets see if I remember some of this... Been a while. I'll just give you the code example I've got. Might be broken, haven't run it recently. Hope it helps.


Say I have a UnitTestSuite that should exclude the category "SlowTest" AND the category "IntegrationTest".

/**

  • By inheriting from IntegrationTestExcluderSuite, this test excludes the IntegrationTest category,
  • in addition to the SlowTest category. */ @ExcludeCategory(SlowTest.class) public class UnitTestsSuite extends IntegrationTestExcluderSuite { }

The extended IntegrationTestExcluderSuite looks like this:

/**

  • This class would not be necessary if @ExcludeCategory could take more than one category!
  • The workaround is to inherit from several suites with one @ExcludeCategory in each one. */ @ExcludeCategory(IntegrationTest.class) public class IntegrationTestExcluderSuite extends CategoryTestSuite { }

And the base category suite:

/**

  • Base Test Suite for all Category-Based Suites */ @RunWith(Categories.class) @SuiteClasses(AllTestsOnClasspath.class) public class CategoryTestSuite {

merland avatar Oct 11 '11 15:10 merland

I actually ended up forking and adding the feature myself. Pull request is in.

ajmath avatar Oct 11 '11 15:10 ajmath

Great. Hope it gets pulled!

merland avatar Oct 12 '11 07:10 merland

Are you sure that inheritance model actually works, from what I can see it just takes the @Include/Exclude of the TestSuite and doesn't take into account the parent. Reproduced by categorising 2 tests one as A, the other as B. Class X @include A and class Z extend X and @include B. Use X to run the Tests and see it will run the tests with B and not a test only with A,B.

dekz avatar Oct 31 '11 04:10 dekz

I second the demand. Again I am willing to provide the code if you see a chance it is going to be accepted.

gaffa avatar Dec 04 '12 08:12 gaffa

@gaffa We are already in progress with this in our pull. The only thing missing is the Javadoc refactoring.

Pls do not work on a code, because we already agreed a concept and the code is ready including the tests. So we know use cases and exact behavior and usage which satisfies the needs of people joined the discussions. We may of course extend discussions if the feature needs to be wider.

I hope we will provide this in next releases.

I would like you to invite into my pull due to the Javadoc and wiki page.

I am very busy with other pull, so your help is welcome in Javadoc. I am going to finish ParallelComputer by today, thus since tomorrow I will concentrate on Categories again. So I would be happy if we join together.

Do you agree with me?

Thx.

Tibor17 avatar Dec 04 '12 09:12 Tibor17

Hi Tibor! I am pretty busy working right now. I would have offered a quick solution but your pull request seems to cover more? Its not linked in this thread, is it?

gaffa avatar Dec 04 '12 09:12 gaffa

@gaffa Hi again, let's move to #503. But as I said, today is not the best time for me.

Tibor17 avatar Dec 04 '12 09:12 Tibor17

@gaffa There were more issues and pulls. Finally we moved only to one. So this is old. In the #503 you can see the history and backtrack all our activities referring to the issues and pulls.

Tibor17 avatar Dec 04 '12 10:12 Tibor17

Fixed by #503 and shipping with 4.12.

marcphilipp avatar Sep 08 '14 17:09 marcphilipp