이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 5. To Test a Route with JUnit


Abstract

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.

Overview

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.

Goals

In this tutorial you will:
  • create a Apache Camel test case
  • run the route with the test case
  • observe the output

Prerequisites

To complete this tutorial you will need:

Creating the test case

To create a new test case:
  1. In Project Explorer, select src/test/java.
  2. Right-click it to open the context menu, and then select New Camel Test Case to open the New Camel JUnit Test Case wizard, as shown in Figure 5.1, “New Camel JUnit Test Case wizard”.

    Figure 5.1. New Camel JUnit Test Case wizard

  3. Make sure the Source folder field contains simple-route/src/test/java.
    Note
    If needed, you can click browse button to find the proper folder.
  4. The Package field defaults to tutorial.simple-route. To include the test case in a different package, enter the name of the package.
  5. In the Camel XML file under test field, enter src/main/resources/META-INF/spring/camelContext.xml, or use browse button to open a file explorer, configured to screen for XML files, to locate the file.
    Note
    The Name field defaults to CamelContextXmlTest for the name of the test file.
  6. Click Next> to open the Test Endpoints page, shown in Figure 5.2, “Test Endpoints page”.

    Figure 5.2. Test Endpoints page

  7. By 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.
  8. Click Finish.
    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.

Running the test

To run the test:
  1. Select the project root, simple-route, in the Project Explorer.
  2. Open the context menu.
  3. Select Run As JUnit Test.
    The JUnit view, shown in Figure 5.3, “JUnit view”, opens in the Eclipse sidebar.

    Figure 5.3. JUnit view

  4. 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.

Further reading

To learn more about:
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat