Speedup tests of play.libs.ws.WSClient that use a play.server.Server #11292
Unanswered
simonlucalandi
asked this question in
Q&A
Replies: 2 comments 1 reply
-
have you tried extracting the server out of your method scope? e.g. play.server.Server server = Server.forRouter((components) -> RoutingDsl.fromComponents(components)
.POST("/").routingTo(request -> ok().sendResource("test1.json")
).build()
);
@Test
public void myTest() {
play.libs.ws.WSClient ws = play.test.WSTestClient.newClient(server.httpPort());
// here we use ws to make a request to "server" and verify the response.
MyClient client = new MyClient(ws);
var response = client.myMethod();
assertAllGood(response);
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
You can dependency inject the |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In our platform, based on PlayFramework 2.8, we have several external API that we call using play.libs.ws.WSClient.
To test the behavior of the WSClient, we start a local play.server.Server, configured to serve the expected resources, something like this:
As we test the behavior for different served resources, we need to start again and again a new
Server
for each test, and the test suite is now slooooow.Starting the server takes around 300-400 ms (measured with the
System.out.println(ZonedDateTime.now())
that you see in the code).Is there a way to speedup the tests? For example I was looking for a a way to reuse the same
Server
, changing only theRouting
, but I can't find a way.Any suggestion is appreciated.
Beta Was this translation helpful? Give feedback.
All reactions