1

I have an unit test like this:

    @Test
    public void callRegisterByForm() {
//  AnyContentAsJson anyContentAsJson = null;
    running(fakeApplication(), new Runnable() {
            @Override
            public void run() {
                Map<String, String> map = new HashMap<String, String>();
                map.put("phoneNumber", "+5103978860");
                map.put("countryCode", "us");

                Result result = routeAndCall(fakeRequest("POST", "/register").withFormUrlEncodedBody(map));
                assertThat(status(result)).isEqualTo(OK);
                assertThat(contentType(result)).isEqualTo("application/json");
                JsonNode jsonResult = Json.parse(contentAsString(result));
                assertThat(jsonResult.get(Config.DEV_REG_STATUS_PARAM).asText()).isEqualTo("OK");
                assertThat(jsonResult.get(Config.DEV_PHONE_NUMBER_PARAM).asText()).isEqualTo("+5103978860");
            }
        });

    }

How do I test the server's controller? I tried to setup a remote java application and use 'play debug run' on console but still not able right click on this test case to run and have the server's controller stop at breakpoints.

This is the image when I right click a test case. It asks me to select a launcher to use. enter image description here

angelokh
  • 9,426
  • 9
  • 69
  • 139

1 Answers1

1

MMMh since I'm using the TypeSafe stack I don't have access to the play executable.

However, I know a way to start the play server in debug mode. Actually I wrote it on my blog here.

`export SBT_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9999` 

will do the trick to have the JVM (running your Play server) listening for one debug connection.

After what, you've said it, you setup a remote application that connect to localhost:9999

In the play console, you'll have the option to

  • launch test and debug (in case you've unit test for your controller)
  • test your app by hand (otherwise)

EDIT

Related to running the test in eclipse, I cannot see how to do since it relies on the classpath and probably some configuration.

However what could be done is to execute play debug test-only test.accounts.MyTest, assuming you've a test called MyTest in the test classpath under the package test.accounts. This will execute only the MyTests's tests.

While starting attach you debugger (remote app) to the jvm in order the walk the code.

Another way might be : * play debug in one console, * attach the debugger * open an another console to execute test-only test.accounts.MyTest as many times as you want.

Andy Petrella
  • 4,345
  • 26
  • 29
  • What is this different from 'play debug run'? For 'play debug run', I already able to launch a local server and have Eclipse to connect to 9999 port for remote debugging. – angelokh Jun 04 '12 at 18:48
  • How ok, it wasn't clear to me... sorry. Hum for your problem, you might (maybe) look at how to debug specs2 test in eclipse ? – Andy Petrella Jun 04 '12 at 20:24
  • Yes for sure, but what type of test did you created ? – Andy Petrella Jun 04 '12 at 21:30
  • Just like the example I posted. It is using Play 2 fakeApplication(). http://www.playframework.org/documentation/2.0/JavaTest – angelokh Jun 04 '12 at 21:46
  • Well well... Actually I'll have to read à bit what does 'test' to help you. Do some look in the svt command will be necessart.... – Andy Petrella Jun 05 '12 at 05:50
  • Hey man, is the last EDIT I did would be ok for you ? It's like a workaround to what you want to do... – Andy Petrella Jun 07 '12 at 06:40
  • 1
    Yes, it works. First, 'play debug' in one console. Attach eclipse to listen to localhost:9999. Then run 'test-only mytest'. – angelokh Jun 11 '12 at 21:51