Right now I’ve been maintaining a second sandbox project where I test concepts and work through roadblocks. But this is not very efficient as I end up having to duplicate a lot of code and am unable to maintain a durable set of regression tests for my game.
I do have a folder of unit tests within my project, but it is impossible to test components of the framework itself as they depend on platform-specific implementations that are not available to the core branch where development takes place.
I have located the PlayN framework’s set of tests. Is it possible to leverage these for testing one’s own project? Is it possible to include two Game classes within one project?
I see this question was raised here, but it never really got a satisfactory response.
You cannot easily write unit tests that are run against the different backends supported by PlayN. Clearly it would be quite a challenge to automatically run your unit tests on an Android phone or iOS device. However, you can write unit tests that run against the Java backend pretty easily.
I generally structure my projects such that my core submodule has a
testdependency onplay n-javaand then I run my unit tests using theplayn-javabackend. I have found this to work reasonably well, though I don’t usually test much that directly interacts with PlayN because it’s hard to unit test visual code. The things I unit test rarely make PlayN calls.You can also unit test against the HTML5 backend, but it’s reaaaaally slow. Look at HTMLUnit.
[edit: since I’m answering this question repeatedly, I’ll add instructions here on how to configure your project to run unit tests against the Java backend]
Add playn-java to your
core/pom.xmlas a test dependency:Add this to your
core/pom.xmlalso:which will properly set up LWJGL when running your unit tests.
Then add this to your unit test:
Now you can access
PlayN.foo()services in your unit tests and they’ll even work.You compile and run your tests from Maven like so:
If you need to run your unit tests on a (Unix) build server, you’ll need to ensure that the build server has a headless X windows installation installed along with the Mesa GL libraries.