Integration Test Configuration in Play Framework


A few days ago I’ve come across a problem while writing integration testing of my play application. My need was like to run unit and Integration test separately, in a normal sbt project, it’s easy to configure it, but I couldn’t find proper documentation about how to do this in play application, because there are difference in the folder structure in both of them.
The reason why I wanted to run unit and integration test cases separately because my integration tests take much more time as they call external web services.
So I came to know one easy solution, which I am going to explain, There are only 2 steps to do this.
1. You need to create a folder in your base directory eg. it, and put your all Integration test cases in that folder.

2. You need to configure your build.sbt file so it can understand where are all integration tests are placed

lazy val root = (project in file("."))
  .settings(routesGenerator := InjectedRoutesGenerator)
  .enablePlugins(PlayScala)
  .configs(ITest)
  .settings( inConfig(ITest)(Defaults.testSettings) : _*)

lazy val ITest = config("it") extend(Test)

scalaSource in ITest := baseDirectory.value / "/it"

On the last line of code we are just configuring to take all integration test cases from the “it” folder of the base directory.

So that’s it 🙂
You just need to hit it:test to run integration tests and simple test  to run the unit test cases.

Cheers!!!

This entry was posted in Integration testing in play framework, Play Framework, Scala, Test, testing, tests. Bookmark the permalink.

One Response to Integration Test Configuration in Play Framework

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s