[2.2.1 Java] Separating Unit from Integration tests using SBT's IntegrationTest functionality

703 views
Skip to first unread message

Sean McClelland

unread,
Nov 4, 2013, 5:52:59 PM11/4/13
to play-fr...@googlegroups.com
Hi,

I have read that you can use test-only to separate out different types of tests. I have been trying to do accomplish something similar while also using jacoco4sbt which uses SBT's built in Unit/Integration test separation. (http://www.scala-sbt.org/0.13.0/docs/Detailed-Topics/Testing)

At this point I have been able to successfully separate out the integration tests and that is working perfectly for the integration tests, but the standard tests still include the integration tests unfortunately. I am very new to Play and SBT, so I am probably just doing something wrong and would appreciate any help anyone could offer.  

Here is the code I have in my build.sbt:

lazy val playTestDependency = "com.typesafe.play" %% "play-test" % play.core.PlayVersion.current % "it"

lazy val itest =
  project in file(".") configs( IntegrationTest ) settings( Defaults.itSettings : _*) settings( libraryDependencies += playTestDependency)
  
sourceDirectory in Test := baseDirectory.value / "test/unit/"

javaSource in Test := baseDirectory.value / "test/unit/"
 
javaSource in IntegrationTest := baseDirectory.value / "test/functional/"

sourceDirectory in IntegrationTest := baseDirectory.value / "test/functional/"


For Jacoco4sbt support I have this below it (Just in case maybe this turns into an overwriting settings issue):

libraryDependencies +=  "org.jacoco" % "org.jacoco.core" % "0.6.3.201306030806" % "it,test"

libraryDependencies +=  "org.jacoco" % "org.jacoco.report" % "0.6.3.201306030806" % "it,test"

jacoco.settings

itJacoco.settings

parallelExecution in jacoco.Config := false

jacoco.reportFormats in jacoco.Config := Seq(
  XMLReport(encoding = "utf-8"),
  HTMLReport())



If I run "show it:defined-tests", I can very clearly see that only my functional.* tests are showing. If I run "show defined-tests", I see tests from both functional.* and unit.*. Any suggestions? At this point I am considering manually creating a filter for test to remove the functional tests, but that seems more like a hack than a proper fix, so I wanted to see if anyone else had any ideas.

Thanks,

-Sean

Rauha Rahkola

unread,
Mar 11, 2014, 4:05:15 AM3/11/14
to play-fr...@googlegroups.com
Thanks for the pointers, I've been stuck for a while on this issue!
I'd like to separate out my tests into different configurations as well (unit, integration, system integration).  Based on your configuration above, here's what I got to work in my project:

// Test Settings
lazy
val SystemIntegrationTest = config ("systest") extend(IntegrationTest)



lazy
val playTestDependency = "com.typesafe.play" %% "play-test" % play.core.PlayVersion.current % "it"



lazy
val testConfigs = project in file(".") configs( SystemIntegrationTest, IntegrationTest
 
) settings( inConfig(SystemIntegrationTest)(Defaults.testSettings) : _*
 
) settings( inConfig(IntegrationTest)(Defaults.itSettings) : _*
 
) settings( libraryDependencies += playTestDependency
  )

testOptions
in Test += Tests.Argument(TestFrameworks.Specs2, "sequential", "true", "junitxml", "console")

testOptions
in Test += Tests.Argument(TestFrameworks.JUnit, "--ignore-runners=org.specs2.runner.JUnitRunner")

javaSource
in SystemIntegrationTest := baseDirectory.value / "test-sys"

resourceDirectory
in SystemIntegrationTest := baseDirectory.value / "conf-sys"

javaSource
in IntegrationTest := baseDirectory.value / "test-it"

resourceDirectory
in IntegrationTest := baseDirectory.value / "conf-it"


I put one class in each of {base}/test-it, {base}/test-sys, and {base}/test/route, then ran the following commands:
[framework] $ show it:defined-tests
[info] Updating {file:/Users/rrahko/git/play-configs/}testConfigs...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] List(Test IntegrationTest : annotation(false, org.junit.Test))
[success] Total time: 7 s, completed Mar 11, 2014 12:55:54 AM
[framework] $ show systest:defined-tests
[info] List(Test SystemIntegrationTest : annotation(false, org.junit.Test))
[success] Total time: 1 s, completed Mar 11, 2014 12:56:01 AM
[framework] $ show defined-tests
[info] List(Test route.RouteManagerTest : annotation(false, org.junit.Test), Test route.RouteManagerTest : annotation(false, org.junit.runner.RunWith))
[success] Total time: 0 s, completed Mar 11, 2014 12:56:07 AM
Reply all
Reply to author
Forward
0 new messages