Junit test with @RunWith (PowerMockRunner.class) fails - "No tests found."

I am trying to find out the reason why I get errors when I try to run some tests that were created and run all the time. This is the Test class:

package com.chw.pxi.impl.oneway.formatter; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.modules.junit4.PowerMockRunner; @RunWith(PowerMockRunner.class) public class OnewayOldFormatterTestsWhy { @Before public void setUp() { } @Test public void test_nothing() { System.out.println("Yep"); } } 

Here is the error when I try to run the test_nothing method by right-clicking on it, select Run As / Junit test.

 java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=test_nothing], {ExactMatcher:fDisplayName=test_nothing(com.chw.pxi.impl.oneway.formatter.OnewayOldFormatterTestsWhy)], {LeadingIdentifierMatcher:fClassName=com.chw.pxi.impl.oneway.formatter.OnewayOldFormatterTestsWhy,fLeadingIdentifier=test_nothing]] from org.junit.internal.requests.ClassRequest@3632be31 at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createFilteredTest(JUnit4TestLoader.java:77) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:68) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:43) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) 

There are many jar files in the build path for this project. I think I should try to create a new project and see if the problem follows. Side of the note - when I run the test by the method in another test that has this - it works fine without the error above:

 @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"dao-tests-context.xml"}) @TransactionConfiguration(transactionManager="transactionManager", defaultRollback=true) //Note: This is a live database test but transactions will be rolled back //except those that invoke methods that require new transactions public class AgencyDaoTests 

If you need more information, please tell me what and how I can do it and get this information for you.

Thanks Michael

+6
source share
1 answer

Regarding the version of 'org.powermock:powermock-api-mockito2:1.6.5' the Powermock version, I managed to work this by moving the @PrepareForTest annotation from the method level to the class level.

+7
source

All Articles