quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.44k stars 2.58k forks source link

Rest Client guide should show how to test the client #9698

Closed adamu closed 5 months ago

adamu commented 4 years ago

I'm looking at the rest client guide.

It demonstrates how to set up a rest client using dependency injection. However, it doesn't demonstrate how to test the client.

It does include tests, but the tests are testing a Rest server endpoint that wraps the use of the rest client. It would be helpful to provide an example of testing the client directly, rather than via a level of indirection via a local server resource.

tobad357 commented 4 years ago

Adding on to this We run tests in parallel and test with MockServer, the problem is there doesn't seem to be an easy way to change the URL/port the clients point to.

We need a way to start a MockServer with a random port and then point the client to that random port. Basically override the config in the test

geoand commented 4 years ago

@adamu can you elaborate a little more on what you would like to see?

@tobad357 you can manually start Wiremock and make the rest-client point to it, see this for example

adamu commented 4 years ago

A test that calls countriesService.getByName(name) and countriesService.getByNameAsync(name) directly from the test, and shows how to assert the results would be useful.

I think that the test tools are likely to be different. The current example is using RestAssured, but for testing the client I think it's more likely that the tester will want to call the client method directly and then perform assertions on the response object (at least, that's how I'm currently approaching it).

geoand commented 4 years ago

@adamu would you like to contribute a documentation Pull Request?

adamu commented 4 years ago

I'm currently working out how to do it nicely on the project I'm working on. Let me finish that (could be a few days), and then post what I'm doing here. If you think it's sensible, I can look at updating the guide.

geoand commented 4 years ago

Sounds like a plan

geoand commented 5 months ago

The documentation now does show how to test the client, so I am going to close this