All Projects → charithe → kafka-junit

charithe / kafka-junit

Licence: Apache-2.0 license
JUnit rule for spinning up a Kafka broker

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to kafka-junit

rules4android
A collection of JUnit 4 Rules for Android Developers 🔬
Stars: ✭ 23 (-76.29%)
Mutual labels:  junit, junit-rule
travis-ci-tutorial-java
Just to learn how to use travis-ci in a java project!
Stars: ✭ 38 (-60.82%)
Mutual labels:  junit
junit.testlogger
JUnit test logger for vstest platform
Stars: ✭ 61 (-37.11%)
Mutual labels:  junit
springboot-rest-api-angularjs-https
REST API https with Spring Boot and Angular JS. Use MySQL, Hibernate and Spring Security.
Stars: ✭ 38 (-60.82%)
Mutual labels:  junit
cdi-test
JUnit extension for easy and efficient testing of CDI components
Stars: ✭ 23 (-76.29%)
Mutual labels:  junit
HiveRunner
An Open Source unit test framework for Hive queries based on JUnit 4 and 5
Stars: ✭ 244 (+151.55%)
Mutual labels:  junit
Spring Boot Testing Strategies
Sample project demonstrating different Test Strategies that can be followed when using Spring Boot.
Stars: ✭ 233 (+140.21%)
Mutual labels:  junit
justtestlah
Dynamic test framework for web and mobile applications
Stars: ✭ 43 (-55.67%)
Mutual labels:  junit
junit5-kubernetes
Use kubernetes pod from your Junit5 test classes
Stars: ✭ 40 (-58.76%)
Mutual labels:  junit
zerocode-hello-world
Zerocode YAML and JSON based declarative steps hello world rest api testing example - soap, database
Stars: ✭ 18 (-81.44%)
Mutual labels:  junit
Learn-to-Code
Learn to Code - for Free
Stars: ✭ 15 (-84.54%)
Mutual labels:  junit
Library-Spring
The library web application where you can borrow books. It's Spring MVC and Hibernate project.
Stars: ✭ 73 (-24.74%)
Mutual labels:  junit
osgi-testsuite
The OSGi Test Suite runs all JUnit tests in a given list of bundles
Stars: ✭ 15 (-84.54%)
Mutual labels:  junit
cactoos-matchers
Elegant object-oriented hamcrest matchers
Stars: ✭ 30 (-69.07%)
Mutual labels:  junit
jpa-unit
JUnit extension to test javax.persistence entities
Stars: ✭ 28 (-71.13%)
Mutual labels:  junit
doc
QuickPerf documentation: https://github.com/quick-perf/doc/wiki/QuickPerf
Stars: ✭ 22 (-77.32%)
Mutual labels:  junit
McTester
An integration testing framework for Minecraft
Stars: ✭ 39 (-59.79%)
Mutual labels:  junit
xunit-to-junit
This Extensible Stylesheet Language Transformations can transform a xUnit.net v2 XML test results file into a JUnit test results file.
Stars: ✭ 21 (-78.35%)
Mutual labels:  junit
junit4git
Junit Extensions for Test Impact Analysis
Stars: ✭ 40 (-58.76%)
Mutual labels:  junit
KDirtyAndroid
A dirty approach for truly client Android applications using Kotlin
Stars: ✭ 17 (-82.47%)
Mutual labels:  junit

Kafka JUnit Build Status Maven Central

Kafka Junit provides helpers for starting and tearing down a Kafka broker during tests.

Please note that version 3.x.x drops Java 7 support and contains breaking API changes.

Version support matrix
Version Kafka Version
1.6 0.8.2.1
1.7 0.8.2.2
1.8 0.9.0.0
2.3 0.9.0.1
2.4 0.10.0.0
2.5 0.10.0.1
3.0.0 0.10.0.1
3.0.1 0.10.0.1
3.0.2 0.10.1.1
3.0.3 0.10.2.0
3.0.4 0.10.2.1
3.1.0 0.11.0.0
3.1.1 0.11.0.1
4.0.0 1.0.0
4.1.0 1.0.0 (Adds support for both Junit 4 and 5)
4.1.1 1.1.0
4.1.2 2.0.0
4.1.3 2.1.0
4.1.4 2.1.1
4.1.5 2.2.0
4.1.6 2.3.0
4.1.7 2.4.0
4.1.8 2.4.1
4.1.9 2.5.0
4.1.10 2.6.0
4.1.11 2.6.0 (Scala 2.13)
4.2.0 2.8.0
4.2.1 3.0.0
4.2.2 3.2.0
4.2.3 3.2.1

Installation

Releases are available on Maven Central.

Maven Central

Snapshot versions containing builds from the latest master are available in the Sonatype snapshots repo.

Javadocs

http://charithe.github.io/kafka-junit/

Usage

JUnit 4

Create an instance of the rule in your test class and annotate it with @Rule. This will start and stop the broker between each test invocation.

@Rule
public KafkaJunitRule kafkaRule = new KafkaJunitRule(EphemeralKafkaBroker.create());

To spin up the broker at the beginning of a test suite and tear it down at the end, use @ClassRule.

@ClassRule
public static KafkaJunitRule kafkaRule = new KafkaJunitRule(EphemeralKafkaBroker.create());

kafkaRule can be referenced from within your test methods to obtain information about the Kafka broker.

@Test
public void testSomething(){
    // Convenience methods to produce and consume messages
    kafkaRule.helper().produceStrings("my-test-topic", "a", "b", "c", "d", "e");
    List<String> result = kafkaRule.helper().consumeStrings("my-test-topic", 5).get();

    // or use the built-in producers and consumers
    KafkaProducer<String, String> producer = kafkaRule.helper().createStringProducer();

    KafkaConsumer<String, String> consumer = kafkaRule.helper().createStringConsumer();

    // Alternatively, the Zookeeper connection String and the broker port can be retrieved to generate your own config
    String zkConnStr = kafkaRule.helper().zookeeperConnectionString();
    int brokerPort = kafkaRule.helper().kafkaPort();
}

EphemeralKafkaBroker contains the core logic used by the JUnit rule and can be used independently.

KafkaHelper contains a bunch of convenience methods to work with the EphemeralKafkaBroker

JUnit 5

JUnit 5 does not have support for Rules, but instead uses the new JUnit 5 Extension Model.

So if you are using JUnit 5 you can use KafkaJunitExtension which provides a kafka broker that is started and stopped for each test.

The extension is configured using the optional class annotation @KafkaJunitExtensionConfig and provides dependency injection for constructors and methods for the classes KafkaHelper and EphemeralKafkaBroker

@ExtendWith(KafkaJunitExtension.class)
@KafkaJunitExtensionConfig(startupMode = StartupMode.WAIT_FOR_STARTUP)
class MyTestClass {

    @Test
    void testSomething(KafkaHelper kafkaHelper) throws ExecutionException, InterruptedException {
        // Convenience methods to produce and consume messages
        kafkaHelper.produceStrings("my-test-topic", "a", "b", "c", "d", "e");
        List<String> result = kafkaHelper.consumeStrings("my-test-topic", 5).get();
        assertThat(result).containsExactlyInAnyOrder("a", "b", "c", "d", "e");

        // or use the built-in producers and consumers
        KafkaProducer<String, String> producer = kafkaHelper.createStringProducer();

        KafkaConsumer<String, String> consumer = kafkaHelper.createStringConsumer();

        // Alternatively, the Zookeeper connection String and the broker port can be retrieved to generate your own config
        String zkConnStr = kafkaHelper.zookeeperConnectionString();
        int brokerPort = kafkaHelper.kafkaPort();
    }
}

Refer to Javadocs and unit tests for more usage examples.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].