此内容没有您所选择的语言版本。

Chapter 8. Creating a new Apache Camel JUnit test case


Overview

A common way of testing routes is to use JUnit. The design time tooling includes a wizard that simplifies creating a JUnit test case for your routes. The wizard uses the endpoints you specify to generate the starting point code and configuration for the test.
Note
After you create the boilerplate JUnit test case, you need to modify it to add expectations and assertions specific to the route that you've created or modified, so the test is valid for the route.

Procedure

To create a new JUnit test case for your route:
  1. In Project Explorer, select the camel-context.xml file in your routing project.
  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 8.1, “New Camel JUnit Test Case wizard”.

    Figure 8.1. New Camel JUnit Test Case wizard

    Entry page of the New Camel JUnit Test Case wizard
    Alternatively, you can open the wizard by selecting File New Other... Fuse Tooling Camel Test Case from the menu bar.
  3. In Source folder, accept the default location of the source code for the test case, or enter another location.
    You can click Browse button to search for a location.
  4. In Package, accept the default package name for the generated test code, or enter another package name.
    You can click Browse button to search for a package.
  5. In Camel XML file under test, accept the default pathname of the routing context file that contains the route you want to test, or enter another pathname.
    You can click Browse button to search for a context file.
  6. In Name, accept the default name for the generated test class, or enter another name.
  7. Select the method stubs you want to include in the generated code.
  8. If you want to include the default generated comments in the generated code, check the Generate comments box.
  9. Click Next button to open the Test Endpoints page. For example, Figure 8.2, “New Camel JUnit Test Case page” shows a route's input and output file endpoints selected.

    Figure 8.2. New Camel JUnit Test Case page

    Example Test Endpoints page
  10. Under Available endpoints, select the endpoints you want to test. Click the checkbox next to any selected endpoint to deselect it.
  11. Click Finish button .
    Note
    If prompted, add JUnit to the build path.
The artifacts for the test are added to your project and appear in Project Explorer under src/test/java. The class implementing the test case opens in the Java editor.

Related topics

New Camel JUnit Test Case
Test Endpoints
Red Hat JBoss Fuse Tooling Tutorials, To Test a Route with JUnit
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.