playframework - Integration test using both WithServer and Server.forRouter -


i'm writing integration test extending class "play.test.withserver". testing api in play service. api sends request different external service retrieving data. don't want send request during integration tests, i'm trying create mock external service using "server.forrouter()".

when mock service running, actual testserver started withserver class not run. there no errors or exceptions. connectexception while connecting testserver.

this issue occurs when i'm creating mock service using server.forrouter() along withserver.

reference: https://www.playframework.com/documentation/2.5.x/javafunctionaltest https://www.playframework.com/documentation/2.5.x/javatestingwebserviceclients

sample code reproduction:

public class homecontrollerintegrationtest extends withserver {  private server server;  @test public void test() throws exception {     logger.error("mock server");     wsclient ws = ws.newclient(-1);     completionstage<wsresponse> response = ws.url("http://localhost:" + server.httpport() + "/hello").get();     logger.error("response mock server = " + response.tocompletablefuture().get().getbody());       logger.error("my test server");     ws = ws.newclient(-1);     response = ws.url("http://localhost:" + testserver.port() + "/status").get();     logger.error("response test server = " + response.tocompletablefuture().get().getbody()); }  @before public void setup() throws exception {     logger.error("before");     server = server.forrouter(new routingdsl()             .get("/hello").routeto(() -> ok("hello world"))             .build(), mode.test, 20000); }  } 


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

unity3d - Fatal error- Monodevelop-Unity failed to start -