Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

dropwizard/dropwizard-testing-junit6

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dropwizard Testing for JUnit 6

This library provides test helpers for Dropwizard applications using JUnit 6.

Usage

Add the dropwizard-testing-junit6 dependency to your pom.xml:

<dependency>
    <groupId>io.dropwizard.modules</groupId>
    <artifactId>dropwizard-testing-junit6</artifactId>
    <version>5.0.0-SNAPSHOT</version>
    <scope>test</scope>
</dependency>

Then, use the DropwizardAppExtension to test your Dropwizard application:

import io.dropwizard.core.Application;
import io.dropwizard.core.Configuration;
import io.dropwizard.core.setup.Environment;
import io.dropwizard.testing.junit6.DropwizardAppExtension;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.core.Response;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import static org.assertj.core.api.Assertions.assertThat;

public class ExampleTest {

    @RegisterExtension
    public static final DropwizardAppExtension<TestConfiguration> EXTENSION =
        new DropwizardAppExtension<>(TestApplication.class, "config.yml");

    @Test
    void testMyApplication() {
        final Client client = EXTENSION.client();
        final Response response = client.target(
            String.format("http://localhost:%d/my-resource", EXTENSION.getLocalPort()))
            .request()
            .get();

        assertThat(response.getStatus()).isEqualTo(200);
        assertThat(response.readEntity(String.class)).isEqualTo("Hello, world!");
    }

    public static class TestApplication extends Application<TestConfiguration> {
        @Override
        public void run(TestConfiguration configuration, Environment environment) {
            environment.jersey().register(new MyResource());
        }
    }

    public static class TestConfiguration extends Configuration {
    }

    @Path("/my-resource")
    public static class MyResource {
        @GET
        public String get() {
            return "Hello, world!";
        }
    }
}

License

This project is licensed under the Apache License, Version 2.0. See the LICENSE file for details.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.