Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to JUnit 5 #505

Open
decebals opened this issue Mar 29, 2019 · 2 comments
Open

Migrate to JUnit 5 #505

decebals opened this issue Mar 29, 2019 · 2 comments
Assignees
Labels
Milestone

Comments

@decebals
Copy link
Member

No description provided.

@decebals decebals added this to the Pippo 2 milestone Mar 29, 2019
@pitschr
Copy link

pitschr commented Apr 20, 2019

When migrating to JUnit 5. I have an idea to provide an annotation e.g. @PippoTest (extends JUnit @Test annotation) and provides a PippoTestClient instance.

Example:

@PippoTest
public void testEndpoint(PippoTestClient client) {
    final var httpClient = HttpClient.newHttpClient(); // using official java.net.HttpClient 

	final var httpRequest = client.newRequestBuilder("/path").GET().build();

	final var response = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString()).body();
	assertThat(response).isEqualTo(..);
}

In this case the user doesn't need to take care of e.g. http://host:port . And when providing the port then JUnit 5 parallelism can be done (otherwise we would able to verify only one test method due single port)

The port should be choosen automatically because you don't know which ports are free on public CI (e.g. Travis CI)

You can check out how it is done:
https://github.com/pitschr/knx-link/blob/master/src/test/java/li/pitschmann/knx/daemon/KnxHttpDaemonTest.java

For this case it would be helpful when we can start Pippo with port = 0 which simply picks up the next free port (otherwise we need a dirty workaround to ensure the thread safety; how I resolved it can be seen here: method startPippo() on MockHttpDaemon ).

The @PippoTest may come with some values / settings. Feel free to reach out me if you want know more details.

@decebals
Copy link
Member Author

Thanks for your sugestion. I think that actual approach with PippoTest (see http://www.pippo.ro/doc/testing.html) is more simple and intuitive. More then that, java.net.HttpClient is a new class that is available only in Java 11 (Pippo is based on Java 8). But the variant with HttpClient (Java new HTTP, Apache HTTP Components, OkHttp, ...) is a very good alternative.

@decebals decebals self-assigned this Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants