You can find some examples here on GitHub . This is from my favorite project written in Scala using Play Framork version 2.1.0.
The key role is as follows:
"Application" should { "work from within a browser" in { running(TestServer(3333), HTMLUNIT) { browser =>
It launches the Play application on port 3333. Before that, you can add the code for your test devices, etc.
If you want sytem to assign a free port for tests, you can look here .
source share