tree: a24a484942c07ec98b30b1b409a0ae556409d01c [path history] [tgz]
  1. camel-test-infra-arangodb/
  2. camel-test-infra-artemis/
  3. camel-test-infra-aws-common/
  4. camel-test-infra-aws-v1/
  5. camel-test-infra-aws-v2/
  6. camel-test-infra-azure-common/
  7. camel-test-infra-azure-storage-blob/
  8. camel-test-infra-azure-storage-queue/
  9. camel-test-infra-cassandra/
  10. camel-test-infra-common/
  11. camel-test-infra-consul/
  12. camel-test-infra-couchbase/
  13. camel-test-infra-couchdb/
  14. camel-test-infra-dispatch-router/
  15. camel-test-infra-elasticsearch/
  16. camel-test-infra-etcd/
  17. camel-test-infra-ftp/
  18. camel-test-infra-google-pubsub/
  19. camel-test-infra-hbase/
  20. camel-test-infra-hdfs/
  21. camel-test-infra-infinispan/
  22. camel-test-infra-jdbc/
  23. camel-test-infra-kafka/
  24. camel-test-infra-messaging-common/
  25. camel-test-infra-minio/
  26. camel-test-infra-mongodb/
  27. camel-test-infra-nats/
  28. camel-test-infra-nsq/
  29. camel-test-infra-parent/
  30. camel-test-infra-postgres/
  31. camel-test-infra-pulsar/
  32. camel-test-infra-rabbitmq/
  33. camel-test-infra-xmpp/
  34. camel-test-infra-zookeeper/
  35. pom.xml
  36. README.md
test-infra/README.md

Test Infrastructure

Simulating the Test Infrastructure

One of the first steps when implementing a new test, is to identify how to simulate infrastructure required for it to run. The test-infra module provides a reusable library of infrastructure that can be used for that purpose.

In general, the integration test leverages the features provided by the project https://www.testcontainers.org/[TestContainers] and uses container images to simulate the environments. Additionally, it may also support running the tests against remote environments as well as, when available, embeddable components. This varies by each component and it is recommended to check the code for additional details.

Implementing new Test Infra

The test code abstracts the provisioning of test environments behind service classes (i.e.: JMSService, JDBCService, etc). The purpose of the service class is to abstract the both the type service (i.e.: Kafka, Strimzi, etc) and the location of the service (i.e.: remote, local, embedded, etc). This provides flexibility to test the code under different circumstances (ie.: using a remote JMS broker or using a local JMS broker running in a container managed by TestContainers). It makes it easier to hit edge cases as well as try different operating scenarios (ie.: higher latency, slow backends, etc).

JUnit 5 manages the lifecycle of the services, therefore each service must be a JUnit 5 compliant extension. The exact extension point that a service must extend is specific to each service. The JUnit 5 https://junit.org/junit5/docs/current/user-guide/[documentation] is the reference for the extension points.

In general, the services should aim to minimize the test execution time and resource usage when running. As such, the https://junit.org/junit5/docs/5.1.1/api/org/junit/jupiter/api/extension/BeforeAllCallback.html[BeforeAllCallback] and https://junit.org/junit5/docs/5.1.1/api/org/junit/jupiter/api/extension/AfterAllCallback.html[AfterAllCallback] should be the preferred extensions whenever possible because they allow the instance of the infrastructure to be static throughout the test execution.

In most cases a specialized service factory class is responsible for creating the service according to runtime parameters and/or other test scenarios constraints. When a service allows different service types or locations to be selected, this should be done via command line properties (-D<property.name>=<value>). For example, when allowing a service to choose between running as a local container or as remote instance, a property in the format <name>.instance.type should be handled. Additional runtime parameters used in different scenarios, should be handled as <name>.<parameter>. More complex services may use the builder pattern to compose the service accordingly.

When a container image is not available via TestContainers, tests can provide their own implementation using officially available images. The license must be compatible with Apache 2.0. If an official image is not available, a Dockerfile to build the service can be provided. The Dockerfile should try to minimize the container size and resource usage whenever possible.

It is also possible to use embeddable components when required, although this usually lead to more code and higher maintenance.