Testing 测试
Testing is a crucial activity in any piece of software development or integration. Typically, Camel users would use various different technologies wired together in a variety of EIPs with different endpoints, languages, bean integration, and dependency injection, so it’s very easy for things to go wrong!. Testing is the crucial weapon to ensure that things work as you would expect.
测试是软件开发或集成中至关重要的活动。通常,Camel 用户会使用各种不同的技术,将它们与不同的 EIP、端点、语言、Bean 集成和依赖注入相结合,因此很容易出现问题!测试是确保事情按照您的期望工作的关键武器。
Camel is a Java library, so you can easily wire up tests in JUnit. However, the Camel project has tried to make the testing of Camel as easy and powerful as possible, so we have introduced the following features.
Camel 是一个 Java 库,因此您可以轻松地在 JUnit 中进行测试。然而,Camel 项目已经尽力使 Camel 的测试变得简单而强大,因此我们引入了以下功能。
Testing modules 测试模块
The following modules are supported:
支持以下模块:
Component 组件 | Description 描述 |
---|---|
JUnit 5: Is an older standalone Java library letting you easily create Camel test cases using a single Java class for all your configuration and routing without. | |
JUnit 5: Used for testing Camel in Camel Main mode | |
JUnit 5: Used for testing Camel with Spring / Spring Boot | |
Camel Test Infra: Camel Test Infra is a set of modules that leverage modern JUnit 5 features to abstract the provisioning and execution of test infrastructure. Among other things, it provides abstraction of the infrastructure (based on Test Containers - being the de-facto successor of the camel-testcontainers components) as well as JUnit 5 extensions for the Camel Context itself. |
If you are using Camel Quarkus then you can find information in its documentation how to do testing with Quarkus and Camel. 如果您正在使用 Camel Quarkus,那么您可以在其文档中找到有关如何使用 Quarkus 和 Camel 进行测试的信息。 |
In all approaches the test classes look pretty much the same in that they all reuse the Camel binding and injection annotations.
在所有的方法中,测试类看起来基本相同,因为它们都重用了 Camel 绑定和注入的注解。
For more details on the different testing modules, then see their respective documentation from the links in the table above. 有关不同测试模块的更多详细信息,请参阅上表中链接的各自文档。 |
Testing functionality 测试功能
Camel provides a set of features that are common to use when writing unit or integration tests with Camel.
Camel 提供了一组常用的功能,用于编写单元测试或集成测试。
Testing endpoints 测试终端点
Camel provides a number of endpoints which can make testing easier.
骆驼提供了一些端点,可以使测试更加容易。
Name 姓名 | Description 描述 |
---|---|
For testing routes and mediation rules using mocks and allowing assertions to be added to an endpoint. | |
For load & soak testing this endpoint provides a way to create huge numbers of messages for sending to components and asserting that they are consumed correctly. | |
Used for automatic load a set of expected message from another endpoint which is then compared to the messages that arrives at this endpoint. |
The main endpoint is the Mock endpoint which allows expectations to be added to different endpoints; you can then run your tests and assert that your expectations are met at the end.
主要的终点是模拟终点,它允许在不同的终点上添加期望;然后您可以运行测试并断言您的期望在最后得到满足。
Stubbing out physical transport technologies
消除物理运输技术
If you wish to test out a route but want to avoid actually using real physical transport (for example to unit test a transformation route rather than performing a full integration test) then the following endpoints can be useful:
如果您希望测试一条路线,但不想实际使用真实的物理交通工具(例如,对转换路线进行单元测试而不是进行完整的集成测试),那么以下端点可能会有用:
Name 姓名 | Description 描述 |
---|---|
Direct invocation of the consumer from the producer so that single threaded (non-SEDA) in VM invocation is performed which can be useful to mock out physical transports | |
Deliver messages asynchronously to consumers via a | |
Works like SEDA but does not validate the endpoint URI, which makes stubbing very easy. |
Testing existing routes 测试现有路线
Camel provides some features to aid during testing of existing routes where you cannot or will not use Mock etc. For example, you may have a production ready route which you want to test with some 3rd party API which sends messages into this route.
Camel 提供了一些功能,用于在测试现有路由时提供帮助,其中您不能或不会使用 Mock 等。例如,您可能有一个准备好的生产路由,您希望使用某些第三方 API 进行测试,该 API 将消息发送到该路由中。
Name 姓名 | Description 描述 |
---|---|
Allows you to be notified when a certain condition has occurred. For example when the route has completed 5 messages. You can build complex expressions to match your criteria when to be notified. | |
Allows you to advice (enhance) an existing route using a RouteBuilder style. For example, you can send (or send and skip) message to a Mock endpoint for validating the message send by Camel is as expected. |
Third Party Testing libraries
第三方测试库
There are a number of third party testing libraries that Camel users have found useful.
有许多第三方测试库被 Camel 用户认为很有用。
Name 姓名 | Description 描述 |
---|---|
Framework for automated integration tests supporting a wide range of message protocols and data formats | |
YAKS is a framework to enable Cloud Native BDD testing on Kubernetes |