0

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)
  • A `Suite` needs to be defined with its own `Runner`. Every test in a `Suite` can have a different `Runner`. – second Nov 02 '19 at 15:00

2 Answers2

1

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 {
}
Ivan Lymar
  • 2,180
  • 11
  • 26
0

Actually when are using the MockitoRunner you cannot run the test cases a suite. Instead they would run individually.