Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm trying to figure out the reason of why I'm getting errors when I'm trying to run some tests that were created and did run a while back. 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-click, choose "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 lots of jar files in the build path for this project. I guess I should try creating a new project and see if the problem follows. A side note - when I run a test on a method in another test that has this - it runs 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 there is additional information needed, please let me know what and how I can go about and get that information for you.

Thanks, Michael

like image 312
schu777 Avatar asked Jan 22 '16 21:01

schu777


1 Answers

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

like image 144
Nikita Barishok Avatar answered Nov 15 '22 21:11

Nikita Barishok