Test JUnit6
Since Camel 4.17
The camel-test-junit6 module is used for unit testing Camel with JUnit 6.
The class org.apache.camel.test.junit6.CamelTestSupport provides a base JUnit class which you would extend and implement your Camel unit test.
Simple unit test example
As shown below is a basic junit test which uses camel-test-junit6. The createRouteBuilder method is used for build the routes to be tested. Then the methods with @Test annotations are JUnit test methods which will be executed. The base class CamelTestSupport has a number of helper methods to configure testing, see more at the Javadoc of this class.
import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit6.CamelTestSupport;
import org.junit.jupiter.api.Test;
public class SimpleMockTest extends CamelTestSupport {
@Test
public void testMock() throws Exception {
getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
template.sendBody("direct:start", "Hello World");
MockEndpoint.assertIsSatisfied(context);
}
@Override
protected RoutesBuilder createRouteBuilder() {
return new RouteBuilder() {
@Override
public void configure() {
from("direct:start").to("mock:result");
}
};
}
} Migrating Camel Tests from JUnit 5 to JUnit 6
Find below some hints to help in migrating camel tests from JUnit 5 to JUnit 6.
Projects using camel-test-junit5 would need to use camel-test-junit6. For instance, maven users would update their pom.xml file as below:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-junit6</artifactId>
<scope>test</scope>
</dependency> Migration Steps
-
Imports of
org.apache.camel.test.junit5.*should be replaced withorg.apache.camel.test.junit6.*
Please check the JUnit User Guide for additional insights about migrating to and writing tests using JUnit 6.