All Projects → JeanBaptisteWATENBERG → junit5-kubernetes

JeanBaptisteWATENBERG / junit5-kubernetes

Licence: other
Use kubernetes pod from your Junit5 test classes

Programming Languages

java
68154 projects - #9 most used programming language
kotlin
9241 projects

Projects that are alternatives of or similar to junit5-kubernetes

webdrivermanager-examples
JUnit tests with Selenium WebDriver and WebDriverManager
Stars: ✭ 94 (+135%)
Mutual labels:  junit, junit5
junit5-demo
Demos for JUnit 5
Stars: ✭ 46 (+15%)
Mutual labels:  junit, junit5
jpa-unit
JUnit extension to test javax.persistence entities
Stars: ✭ 28 (-30%)
Mutual labels:  junit, junit5
testing-spring-boot-applications-masterclass
🍃 Everything You Need to Know About Testing Spring Boot Applications
Stars: ✭ 185 (+362.5%)
Mutual labels:  junit, junit5
bdd
JUnit 5 based BDD library to create and run stories and behaviors a.k.a BDD specification tests
Stars: ✭ 25 (-37.5%)
Mutual labels:  junit, junit5
ForgeModdingSkeleton
Skeletons for building Forge mods
Stars: ✭ 21 (-47.5%)
Mutual labels:  junit, junit5
spring-jooq-flyway-testcontainers-junit5
🚀 Example project with configured Spring Boot, JooQ, TestContainers, MySQL container and JUnit5
Stars: ✭ 29 (-27.5%)
Mutual labels:  junit, junit5
osgi-test
Testing support for OSGi. Includes JUnit 4 and JUnit 5 support and AssertJ support.
Stars: ✭ 22 (-45%)
Mutual labels:  junit, junit5
flyway-junit5-extensions
Flyway JUnit 5 Extension to clean / migrate your database in tests.
Stars: ✭ 14 (-65%)
Mutual labels:  junit, junit5
aws-junit5
JUnit 5 extensions for AWS
Stars: ✭ 18 (-55%)
Mutual labels:  junit5
Learn-to-Code
Learn to Code - for Free
Stars: ✭ 15 (-62.5%)
Mutual labels:  junit
Spring Boot Testing Strategies
Sample project demonstrating different Test Strategies that can be followed when using Spring Boot.
Stars: ✭ 233 (+482.5%)
Mutual labels:  junit
junit.testlogger
JUnit test logger for vstest platform
Stars: ✭ 61 (+52.5%)
Mutual labels:  junit
zerocode-hello-world
Zerocode YAML and JSON based declarative steps hello world rest api testing example - soap, database
Stars: ✭ 18 (-55%)
Mutual labels:  junit
doc
QuickPerf documentation: https://github.com/quick-perf/doc/wiki/QuickPerf
Stars: ✭ 22 (-45%)
Mutual labels:  junit
HiveRunner
An Open Source unit test framework for Hive queries based on JUnit 4 and 5
Stars: ✭ 244 (+510%)
Mutual labels:  junit
Quickperf
QuickPerf is a testing library for Java to quickly evaluate and improve some performance-related properties
Stars: ✭ 231 (+477.5%)
Mutual labels:  junit
Junit Dataprovider
A TestNG like dataprovider runner for JUnit with many additional features
Stars: ✭ 226 (+465%)
Mutual labels:  junit
j8spec
Library that allows tests written in Java to follow the BDD style introduced by RSpec and Jasmine.
Stars: ✭ 45 (+12.5%)
Mutual labels:  junit
dynatest
Simplest Most Powerful Testing Framework For Kotlin
Stars: ✭ 22 (-45%)
Mutual labels:  junit5

Junit5-kubernetes Java CI with Gradle

Inspired by https://www.testcontainers.org/, this project aims at using a kubernetes pod directly form your junit5 test classes. It hence fills the lack of kubernetes support of testcontainers while the library study it's implementation (testcontainers/testcontainers-java#1135).

Maven installation

<dependency>
  <groupId>com.github.jeanbaptistewatenberg.junit5kubernetes</groupId>
  <artifactId>core</artifactId>
  <version>2.3.2-beta</version>
  <scope>test</scope>
</dependency>

Gradle installation

testImplementation("com.github.jeanbaptistewatenberg.junit5kubernetes:core:2.3.2-beta")

NEW 2.3.2-beta Usage

Version 2.3.2-beta introduces a new java property junitKubernetesUsePortService, when it is set to true it will create a NodePort service aside of your pods in order to ease pods access from outside your kubernetes cluster.

I am going to test this approach in the upcoming days and stabilize it if I see some benefits from using it.

If you want to test it out you can refer to TestUsingNodePortService.java and feel free to report any issues.

Usage

@JunitKubernetes
public class Test {

    private static final String NGINX_PORT = "nginx-80";
    private final PortMapper portMapper = new PortMapper();

    @KubernetesObject
    private KubernetesGenericObject pod = new GenericPodBuilder()
            .withNewSpec()
            .addNewContainer()
            .withName("demonginx")
            .withImage("nginx")
            .addNewPort()
            .withHostPort(portMapper.computeAvailablePort(NGINX_PORT))
            .withContainerPort(80)
            .endPort()
            .endContainer()
            .endSpec()
            .withWaitStrategy(new WaitRunningStatusStrategy())
            .build();

    @Test
    void should_start_a_pod() throws IOException {
        assertThat(pod.getObjectHostIp()).isNotBlank();
        assertThat(portMapper.getComputedPort("nginx-80")).isNotNull();

        URL url = new URL("http://" + pod.getObjectHostIp() + ":" + portMapper.getComputedPort(NGINX_PORT));
        int status = responseStatus(url);
        assertThat(status).isEqualTo(200);
    }
}

By default Junit5-kubernetes will create a new pod for each of your tests. If you want to reuse your pod accross your tests you can simply switch your @KubernetesObject to be static.

GenericPodBuilder

GenericPodBuilder relies on the official kubernetes java client. You can use it similarly as V1PodBuilder.

PortMapper

In order to use a port you need to expose it to the host machine. PortMapper class is here to pick an available port for you and name it with the name you provided. You can then use this port by calling portMapper.getComputedPort(PORT_NAME).

WaitStrategy

A WaitStrategy define the conditions your pod should meet before being considered as ready to execute your tests against.

Available WaitStrategies are :

Configuration options

You can configure the extension using JVM system properties. Available properties are :

  • kubernetesNamespace : namespace in which you want the extension to deploy the objects
  • kubernetesPullSecrets : Comma separated pull secrets (eg : -DkubernetesPullSecrets=secret1,secret2)
  • junitKubernetesDebug : print advanced logs about what the extension does, however it will make waiters fails as kubernetes java client watch is not compatible with this option
  • junitKubernetesDisableHttp2 : it will set kubernetes client to use only http 1 instead of 2

Common helpers

PostgreSQL helper

Maven

<dependency>
  <groupId>com.github.jeanbaptistewatenberg.junit5kubernetes</groupId>
  <artifactId>postgresql</artifactId>
  <version>2.3.2-beta</version>
</dependency>

Gradle

testImplementation("com.github.jeanbaptistewatenberg.junit5kubernetes:postgresql:2.3.2-beta")

Usage

@JunitKubernetes
public class Test {

    @KubernetesObject
    private PostgreSQLPod pod = new PostgreSQLPod();

    @Test
    void should_start_a_pod() throws IOException {
        HikariConfig hikariConfig = new HikariConfig();
        hikariConfig.setJdbcUrl(pod.getJdbcUrl());
        hikariConfig.setUsername(pod.getUsername());
        hikariConfig.setPassword(pod.getPassword());

        try (HikariDataSource ds = new HikariDataSource(hikariConfig)) {
            Statement statement = ds.getConnection().createStatement();
            statement.execute("SELECT 1");
            ResultSet resultSet = statement.getResultSet();
            resultSet.next();

            int resultSetInt = resultSet.getInt(1);
            assertThat(resultSetInt).isEqualTo(1);
        }
    }
}

RabbitMQ helper

Maven

<dependency>
  <groupId>com.github.jeanbaptistewatenberg.junit5kubernetes</groupId>
  <artifactId>rabbitmq</artifactId>
  <version>2.3.2-beta</version>
</dependency>

Gradle

testImplementation("com.github.jeanbaptistewatenberg.junit5kubernetes:rabbitmq:2.3.2-beta")

Usage

@JunitKubernetes
public class Test {

    @KubernetesObject
    private RabbitMQPod pod = new RabbitMQPod();

    @Test
    void should_start_a_pod() throws IOException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setUri(pod.getAmqpUrl());
        factory.setUsername(pod.getAdminUsername());
        factory.setPassword(pod.getAdminPassword());
        Connection conn = factory.newConnection();

        assertThat(conn).isNotNull();
    }
}

ElasticSearch helper

Maven

<dependency>
  <groupId>com.github.jeanbaptistewatenberg.junit5kubernetes</groupId>
  <artifactId>elasticsearch</artifactId>
  <version>2.3.2-beta</version>
</dependency>

Gradle

testImplementation("com.github.jeanbaptistewatenberg.junit5kubernetes:elasticsearch:2.3.2-beta")

Usage

@JunitKubernetes
public class Test {

    @KubernetesObject
    private ElasticSearchPod pod = new ElasticSearchPod();

    @Test
    void should_start_a_pod() throws IOException {
            HttpHost httpHost = new HttpHost(pod.getObjectHostIp(), pod.getHttpPort(), "http");
            RestHighLevelClient restHighLevelClient = new RestHighLevelClient(RestClient.builder(httpHost));
            IndexRequest indexRequest = new IndexRequest("anyindice");
            indexRequest.source(Collections.singletonMap("key","value"));
            IndexResponse response = restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
            assertThat(response.status()).isEqualTo(RestStatus.CREATED);
    }
}
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].