The Test Module for Play!Framework helps you write tests quicker, is a cleaner and reusable manner.
Play provides an environment for testing. However that environment is full of hard-coded strings, and the code you write is neither reusable nor maintainable.
When you start a new Play application, Play generates a sample code for you that looks like this :
Response response = GET("/"); assertIsOk(response); assertContentType("text/html", response); assertCharset("utf-8", response);
I have several problems with this code.
My WishesI wish I could simply call the controller's function.
In the example above, the path "/" will direct me to controller "Application" and action "index". I wish I could simply call Application.index() and that's it. However, for someone outside of Play it will be hard to implement if not impossible.
The reason for it being so hard lies in the instrumentation technic which is massively used all around Play and the fact that the methods are static.
I will not elaborate this topic here, nor will I talk about why Play chose to implement the actions in static methods, which are not OO by nature. I believe that Singletons would've made a much better choice.
Due to all these difficulties, I will settle for the following syntax
ApplicationTestController c = new ApplicationTestController(); c.index().isOk().is(UTF8).is(HTML);
My module allows you to have similar syntax to this.
In this syntax I know exactly which function is called. I don't care which Path is used, and definitely not which method (GET/POST).
I know which arguments to use with a simple "auto complete". If I change the signature of the controller I can simply refactor my "TestApplicationController" to modify the test easily accordingly.
Note I am not mentioning Response anywhere.. I have less code, HTML and UTF8 are Enums, so I know exactly what my options are.
All the info and tutorials you need can be found by code samples, and wiki pages available to you in GitHub (link below).
Since this little (10 classes.. ) project of mine combines cool technologies like Play and CGLib, I will write a series of posts about how I wrote it. (links below).