2

Is it possible to run only some methods (not all) from a test case in Junit4 (Eclipse)? I have 2 test cases and I want to implement a test suite which contains all the methods from one test case (I did that by adding the @Category annotation to all the tests from the first test case and then in the suite i used @IncludeCategory) and some methods from the second one.

Thank you!

xavier
  • 177
  • 3
  • 15
  • It is not directly related, but this is a way to [compute 'Tests by Category' counter](https://stackoverflow.com/a/53778167/10524205). – Bsquare ℬℬ Jan 18 '19 at 12:49

1 Answers1

0

Yes, it is possible. Just put the @Category annotation containing the same marker:

  • on class level - on a class from which all methods should be included in a suite.
  • on method level - annotate selected methods within a class when not all of them should be included in a suite.

...and include that category within your suite.

I believe that first SlowTestSuite class from an example in Category documentation shows the situation you've asked about - it runs all tests from B and only some from A.

Jakub Ch.
  • 3,577
  • 3
  • 24
  • 43