Question

One option for running my tests in my Play! application is by executing the command play auto-test.

One of the ways Play seems to identify tests to run is to find all test classes with the super class play.test.UnitTest (or another Play equivalent). Having a test class extend UnitTest seems to come with some overhead as shown by this bit of stuff spat out in the console:

INFO   info, Starting C:\projects\testapp\.
WARN   warn, Declaring modules in application.conf is deprecated. Use dependencies.yml instead (module.secure)
INFO   info, Module secure is available (C:\play-1.2.1\modules\secure)
INFO   info, Module spring is available (C:\projects\testapp\.\modules\spring-1.0.1)
WARN   warn, Actually play.tmp is set to null. Set it to play.tmp=none
WARN   warn, You're running Play! in DEV mode
INFO   info, Connected to jdbc:h2:mem:play;MODE=MYSQL;LOCK_MODE=0
INFO   info, Application 'Test App' is now started !

Obviously having a Play environment for tests that requires such a setup is useful, however, if I have a test class that tests production code that executes logic that does not require a Play environment I don't want to have to extend UnitTest so that I can avoid the overhead of starting up a Play environment.

If I have a test class that does not extend UnitTest then it does not get executed by the command play auto-test. Is there a way to get the play auto-test command to execute all tests regardless of whether I extend Play's UnitTest?

Edit: Someone has actually raised a ticket for this very issue

Was it helpful?

Solution

the short answer: no. A tad longer answer: no unless you change code in the framework. The autotest is an Ant task that sets the server and triggers the testing, but it's not using the ant task, so it won't detect (by default) your 'normal' unit tests.

You have two options: either you add an extra task to the Ant file of Play to run unit tests via the task (you will need to include the relevant jars too) or you edit the code used to launch the Play test environment.

Both imply changing the framework to a certain level. Although giving that you are using Play, I wonder why you should not have all your tests follow the Play pattern...

OTHER TIPS

If these tests doesn't require any Play! feature, why don't you put them on a library ? With your example (math add) : create a calculator.jar package, and build it with Ant or Maven after running tests. Like this, you can use your library in several Play! projects (or Spring, Struts, ... if you want.

I really don't get why the problem itself is even debatable. Having simple and small unit tests (even in the web-part of your project) is the most normal thing to do. The extra overhead of framework initialisation slows down your roundtrips significantly if you have many tests. As it can be seen in the ticket, the current workaround is to make your unit tests extend org.junit.Assert instead of play.test.UnitTest

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top