I have three test classes to test my controller, service and Kafka Messaging. When I run the Kafka messaging standalone, it works. But when I run all my test files together, the Kafka test class passes as long as it is the first one that gets executed otherwise it fails.
I would like to order the execution of test classes by making sure that Kafka test class always is the first one to execute.
How can I achieve that? With Test suites?? Is there any other way? My application is built using Micronaut, Java 8.
The order of tests run by JUnit is undefined. You must write your tests such that they can run independently.
First, Stop pretending that an integration test (i.e. one that actually calls Kafka) is a unit test. If you are calling something outside the method being tested, then you are running integration tests.
Possible solutions include:
@Test
and have it call methods in your existing "test classes" in the desired order.