1

Given this Test Class

    @PowerMockIgnore("UnitTest")
    @Category(UnitTest.class)
    @RunWith(PowerMockRunner.class)
    public class SomeClass {

       @Test
       @Category(SlowTest.class)
       public void SlowMethod(){...}
    }

And a Test Suite

   @RunWith(Categories.class)
   @SuiteClasses({AllUnitTestSuite.class})
   @ExcludeCategory(SlowTest.class)
   public class FastUnitTestSuite {

   }

When I run the FastUnitTestSuite it runs the SlowMethod also despite it is in SlowTest Category. I can exclude slow Test Classes using PowerMockIgnore and multiple categories. How could I exclude the slow test methods while using PowerMockRunner?

Matthew Farwell
  • 60,889
  • 18
  • 128
  • 171
apreg
  • 637
  • 8
  • 18

3 Answers3

1

Thank you gontard! Here is what I changed:

@PowerMockIgnore({ "org.mockito.*" })
@Category(UnitTest.class)

public class SomeClass {

   @Rule
   public PowerMockRule rule = new PowerMockRule(); //it has to be public

   @Test
   @Category(SlowTest.class)
   public void SlowMethod(){...}
}

I had to add these libs also to my classpath: powermock-module-junit4-rule, powermock-classloading-base, powermock-classloading-xstream, xpp3_min

apreg
  • 637
  • 8
  • 18
1

This issue due to below line in Categories. CategoryFilter file under method hasCorrectCategoryAnnotation

if (fIncluded == null || fIncluded.isAssignableFrom(each))
  • this will fail even though the class type is same or under inheritance because fIncluded is loaded by Categories classloader and each is loaded by PowerMockRunner class loader.

Probably we need fix this logic

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Velmurugan
  • 11
  • 1
0

When you want to use PowerMock with a different test runner, you should use the powermock junit rule: PowerMockRule.

You could see an example with a SpringJUnit4ClassRunner in this answer.

Community
  • 1
  • 1
gontard
  • 28,720
  • 11
  • 94
  • 117