Overview
This guide will walk you through creating a complete integration test using TNB. You’ll write a test that automatically deploys Kafka, produces messages, consumes them, and validates the results.Prerequisites
- Java 17 or higher
- Maven 3.6+
- Basic familiarity with JUnit 5
Create your first test
Add TNB dependency
Add the TNB Kafka service to your
pom.xml:pom.xml
See the installation guide for more dependency options including BOM imports.
What’s happening
Let’s break down the test code:Service creation
ServiceFactory.create() method:
- Determines the deployment environment (local by default)
- Creates the appropriate service implementation
- Registers JUnit 5 lifecycle hooks for automatic deployment
The service field must be
static and annotated with @RegisterExtension to work with JUnit 5’s extension model.Validation API
produce(topic, message)- Sends a message to a Kafka topicconsume(topic)- Polls all messages from a topic- Both methods handle the complexity of Kafka producers/consumers internally
Service lifecycle
TNB manages the service lifecycle automatically:Before all tests
The
@BeforeAll hook:- Deploys the Kafka container
- Waits for Kafka to be ready
- Opens client connections
During tests
Your test code:
- Uses the validation API to interact with Kafka
- Performs assertions on results
Testing with multiple services
You can use multiple services in a single test:MultiServiceTest.java
Switching to OpenShift
To run the same test on OpenShift instead of locally:- Deploy Kafka as an OpenShift deployment
- Create routes for external access
- Run your tests against the cluster deployment
Customizing services
Some services support configuration:Next steps
Core concepts
Learn about accounts, clients, and validation objects
Available services
Explore all 50+ supported System-X services
Configuration
Configure service images, credentials, and deployment options
Camel testing
Test Apache Camel applications with TNB