This tutorial walks you through the process of using the New Camel Test Case wizard to create a test case for your route and using it test the route.
The New Camel JUnit Test Case wizard generates a boilerplate JUnit test case. This means that when you create or modify a route (for example, adding more processors to it), you'll need to modify the generated test case to add expectations and assertions specific to the new route you've created, so the test is valid for the route.
In this tutorial you will:
create a Apache Camel test case
run the route with the test case
observe the output
To complete this tutorial you will need:
the simple-route project you created in To Add a Content-Based Router
To create a new test case:
In Project Explorer, select
src/test/java
.
Right-click it to open the context menu, and then select New Camel JUnit Test Case wizard, as shown in Figure 15, “New Camel JUnit Test Case wizard”.
> to open theMake sure the Source folder field contains
simple-route/src/test/java
.
![]() | Note |
---|---|
If needed, you can click |
The Package field defaults to
tutorial.simple-route
. To include the test case in a
different package, enter the name of the package.
In the Camel XML file under test field, enter
src/main/resources/META-INF/spring/camelContext.xml
,
or use to open a file explorer, configured to screen for XML
files, to locate the file.
![]() | Note |
---|---|
The Name field defaults to
|
Click Test Endpoints page, shown in Figure 16, “Test Endpoints page”.
to open theBy default, all endpoints are selected and will be included in the test case. You can select or deselect all endpoints by clicking the Select All or Deselect All button, or you can select and deselect individual endpoints by clicking the check box next to each.
Click
.![]() | Note |
---|---|
If prompted, add JUnit to the build path. |
The artifacts for the test are added to your project, and the class implementing the test case opens in the Java editor.
To run the test:
Select the project root, simple-route
, in the
Project Explorer.
Open the context menu.
Select
> .The JUnit view, shown in Figure 17, “JUnit view”, opens in the Eclipse sidebar.
Examine the output and take action to resolve any test failures.
![]() | Note |
---|---|
You may have to run this boilerplate test twice before it runs without a failure. |