Search code examples
junitmockitotest-suite

How to create test suite for Mockito when we are writing junit


How to create test suite for Mockito , when we have multiple class which are having mockito test cases

I have tried using @RunWith(MockitoJUnitRunner.class) with @SuiteClasses({SampleTest.class,DummyTest.class}) but the throwing error . When i run individually it runs fine .

@RunWith(MockitoJUnitRunner.class)
@SuiteClasses({SampleTest.class,DummyTest.class})
public class TestSuiteExample
{
}
org.mockito.exceptions.base.MockitoException: 

No tests found in LoginHistoryBLTestSuite
Is the method annotated with @Test?
Is the method public?

    at org.mockito.internal.runners.RunnerFactory.create(RunnerFactory.java:75)
    at org.mockito.internal.runners.RunnerFactory.createStrict(RunnerFactory.java:40)
    at org.mockito.junit.MockitoJUnitRunner.<init>(MockitoJUnitRunner.java:154)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)

Solution

  • To create test suite specifying classes you can use:

    @RunWith(JUnitPlatform.class)
    @SelectClasses( { ServiceTest.class, ControllerTest.class } )
    public class Suite {
    }
    

    or specifying packages:

    @RunWith(JUnitPlatform.class)
    @SelectPackages( { "com.service","com.controller" } )
    public class Suite {
    }