Alex Rivera | Logout

Declaring a Test Dependency in Play!

Asked 2011-06-01T04:28:09.567
9

Is there a way to declare a test dependency in the dependencies.yml file for the Play! Framework? I don't see any information about test dependencies in the documentation.

For example, I may want to use a testing library such as Mockito but not have its classes used in production for obvious reasons.

Edit
Report

1 Answer

9

It seems that you can define dependencies per Play framework ID, similar to how you can define settings for a specific ID in the application.conf file. To do this, you need to add an additional id attribute to your dependency definition.

For example, if you wanted to only include mockito-core in environments with a framework ID of test, your dependencies.yml file would look like the following:

require:
    - org.mockito -> mockito-core 1.8.5:
        id: test

You can get this to work when using a single machine as well, although you have to be a bit more deliberate about it. To test with your test-only dependencies, you'd define your dependency with id: test and then run:

play dependencies --%test --sync
play test

Then, to switch back to production, you'd run:

play dependencies --sync
play run

The downside is that you have to remember to sync your dependencies every time you switch between test and production modes, but I think that this is currently the best you can do if you want to make sure that the dependency is only on the classpath when in test mode.

answered 2011-06-01T04:57:16.313

Your Answer