I wanted to see if all my test are passing after git merge
, and noticed that sbt test
failed. All of those tests are the ones that are using Spring context.
As to not load Spring context for every test I created the following trait:
import org.springframework.context.support.ClassPathXmlApplicationContext
trait Neo4jSpringContext {
val context = Neo4jSpringContext.context
}
object Neo4jSpringContext {
val context = new ClassPathXmlApplicationContext("testNeo4jApplicationContext.xml")
}
and in my tests I am using it as follows:
class CreateRetrieveAirplaneAndLegsSpec extends Specification with Neo4jSpringContext with NoTimeConversions
Now, in the logs I can see that the context is being set up (logging information) but then I am facing the error:
[error] Could not create an instance of persistence.list.neo4j.CreateRetrieveAirplaneAndLegsSpec
[error] caused by java.lang.Exception: Could not instantiate class persistence.list.neo4j.Neo4jDuplicateFlightDesignatorCheckSpec: Could not initialize class persistence.common.neo4j.Neo4jSpringContext$
[error] org.specs2.reflect.Classes$class.liftedTree1$1(Classes.scala:104)
[error] org.specs2.reflect.Classes$class.tryToCreateObjectEither(Classes.scala:93)
[error] org.specs2.reflect.Classes$.tryToCreateObjectEither(Classes.scala:213)
[error] org.specs2.specification.SpecificationStructure$$anonfun$createSpecificationEither$2.apply(BaseSpecification.scala:118)
[error] org.specs2.specification.SpecificationStructure$$anonfun$createSpecificationEither$2.apply(BaseSpecification.scala:118)
[error] scala.Option.getOrElse(Option.scala:120)
[error] org.specs2.specification.SpecificationStructure$.createSpecificationEither(BaseSpecification.scala:118)
[error] org.specs2.runner.TestInterfaceRunner.runSpecification(TestInterfaceRunner.scala:59)
[error] org.specs2.runner.TestInterfaceRunner.run(TestInterfaceRunner.scala:54)
[error] sbt.RunnerWrapper$1.runRunner(FrameworkWrapper.java:200)
[error] sbt.RunnerWrapper$1.execute(FrameworkWrapper.java:236)
[error] sbt.TestRunner.runTest$1(TestFramework.scala:84)
[error] sbt.TestRunner.run(TestFramework.scala:94)
[error] sbt.TestFramework$$anon$2$$anonfun$$init$$1$$anonfun$apply$8.apply(TestFramework.scala:224)
[error] sbt.TestFramework$$anon$2$$anonfun$$init$$1$$anonfun$apply$8.apply(TestFramework.scala:224)
[error] sbt.TestFramework$.sbt$TestFramework$$withContextLoader(TestFramework.scala:212)
[error] sbt.TestFramework$$anon$2$$anonfun$$init$$1.apply(TestFramework.scala:224)
[error] sbt.TestFramework$$anon$2$$anonfun$$init$$1.apply(TestFramework.scala:224)
[error] sbt.TestFunction.apply(TestFramework.scala:229)
[error] sbt.Tests$.sbt$Tests$$processRunnable$1(Tests.scala:211)
[error] sbt.Tests$$anonfun$makeSerial$1.apply(Tests.scala:217)
[error] sbt.Tests$$anonfun$makeSerial$1.apply(Tests.scala:217)
[error] sbt.std.Transform$$anon$3$$anonfun$apply$2.apply(System.scala:45)
[error] sbt.std.Transform$$anon$3$$anonfun$apply$2.apply(System.scala:45)
[error] sbt.std.Transform$$anon$4.work(System.scala:64)
[error] sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
[error] sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
[error] sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
[error] sbt.Execute.work(Execute.scala:244)
[error] sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
[error] sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
[error] sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
[error] sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
[error] java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
[error] java.util.concurrent.FutureTask.run(FutureTask.java:166)
[error] java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
[error] java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
[error] java.util.concurrent.FutureTask.run(FutureTask.java:166)
[error] java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
[error] java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
[error] java.lang.Thread.run(Thread.java:724)
[error] caused by java.lang.NoClassDefFoundError: Could not initialize class persistence.common.neo4j.Neo4jSpringContext$
[error] persistence.common.neo4j.Neo4jSpringContext$class.$init$(Neo4jSpringContext.scala:6)
[error] persistence.list.neo4j.Neo4jDuplicateFlightDesignatorCheckSpec.<init>(Neo4jDuplicateFlightDesignatorCheckSpec.scala:12)
[error] sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[error] sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
[error] sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[error] java.lang.reflect.Constructor.newInstance(Constructor.java:526)
[error] org.specs2.reflect.Classes$class.createInstanceFor(Classes.scala:157)
[error] org.specs2.reflect.Classes$.createInstanceFor(Classes.scala:213)
[error] org.specs2.reflect.Classes$$anonfun$createInstanceOfEither$1.apply(Classes.scala:147)
[error] org.specs2.reflect.Classes$$anonfun$createInstanceOfEither$1.apply(Classes.scala:147)
[error] scala.Option.map(Option.scala:145)
[error] org.specs2.reflect.Classes$class.createInstanceOfEither(Classes.scala:147)
[error] org.specs2.reflect.Classes$.createInstanceOfEither(Classes.scala:213)
[error] org.specs2.reflect.Classes$class.org$specs2$reflect$Classes$$createInstanceForConstructor(Classes.scala:120)
[error] org.specs2.reflect.Classes$$anonfun$5.apply(Classes.scala:98)
[error] org.specs2.reflect.Classes$$anonfun$5.apply(Classes.scala:98)
[error] scala.collection.GenSeqViewLike$Mapped$class.apply(GenSeqViewLike.scala:48)
[error] scala.collection.SeqViewLike$$anon$3.apply(SeqViewLike.scala:78)
[error] scala.collection.GenSeqViewLike$Filtered$class.apply(GenSeqViewLike.scala:91)
[error] scala.collection.SeqViewLike$$anon$5.apply(SeqViewLike.scala:80)
[error] scala.collection.GenSeqViewLike$Mapped$class.apply(GenSeqViewLike.scala:48)
[error] scala.collection.SeqViewLike$$anon$3.apply(SeqViewLike.scala:78)
[error] org.specs2.reflect.Classes$class.liftedTree1$1(Classes.scala:103)
[error] org.specs2.reflect.Classes$class.tryToCreateObjectEither(Classes.scala:93)
[error] org.specs2.reflect.Classes$.tryToCreateObjectEither(Classes.scala:213)
[error] org.specs2.specification.SpecificationStructure$$anonfun$createSpecificationEither$2.apply(BaseSpecification.scala:118)
[error] org.specs2.specification.SpecificationStructure$$anonfun$createSpecificationEither$2.apply(BaseSpecification.scala:118)
[error] scala.Option.getOrElse(Option.scala:120)
[error] org.specs2.specification.SpecificationStructure$.createSpecificationEither(BaseSpecification.scala:118)
[error] org.specs2.runner.TestInterfaceRunner.runSpecification(TestInterfaceRunner.scala:59)
[error] org.specs2.runner.TestInterfaceRunner.run(TestInterfaceRunner.scala:54)
[error] sbt.RunnerWrapper$1.runRunner(FrameworkWrapper.java:200)
[error] sbt.RunnerWrapper$1.execute(FrameworkWrapper.java:236)
[error] sbt.TestRunner.runTest$1(TestFramework.scala:84)
[error] sbt.TestRunner.run(TestFramework.scala:94)
[error] sbt.TestFramework$$anon$2$$anonfun$$init$$1$$anonfun$apply$8.apply(TestFramework.scala:224)
[error] sbt.TestFramework$$anon$2$$anonfun$$init$$1$$anonfun$apply$8.apply(TestFramework.scala:224)
[error] sbt.TestFramework$.sbt$TestFramework$$withContextLoader(TestFramework.scala:212)
[error] sbt.TestFramework$$anon$2$$anonfun$$init$$1.apply(TestFramework.scala:224)
[error] sbt.TestFramework$$anon$2$$anonfun$$init$$1.apply(TestFramework.scala:224)
[error] sbt.TestFunction.apply(TestFramework.scala:229)
[error] sbt.Tests$.sbt$Tests$$processRunnable$1(Tests.scala:211)
[error] sbt.Tests$$anonfun$makeSerial$1.apply(Tests.scala:217)
[error] sbt.Tests$$anonfun$makeSerial$1.apply(Tests.scala:217)
[error] sbt.std.Transform$$anon$3$$anonfun$apply$2.apply(System.scala:45)
[error] sbt.std.Transform$$anon$3$$anonfun$apply$2.apply(System.scala:45)
[error] sbt.std.Transform$$anon$4.work(System.scala:64)
[error] sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
[error] sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:237)
[error] sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:18)
[error] sbt.Execute.work(Execute.scala:244)
[error] sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
[error] sbt.Execute$$anonfun$submit$1.apply(Execute.scala:237)
[error] sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:160)
[error] sbt.CompletionService$$anon$2.call(CompletionService.scala:30)
[error] java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
[error] java.util.concurrent.FutureTask.run(FutureTask.java:166)
[error] java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
[error] java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
[error] java.util.concurrent.FutureTask.run(FutureTask.java:166)
[error] java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
[error] java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
[error] java.lang.Thread.run(Thread.java:724)
I was first thinking that there may be some problem because of parallel execution of tests in sbt, but parallelExecution in Test := false
didn't help -- the tests keep failing.
Interestingly, if I execute the tests in IntelliJ IDEA everything works and hence face no errors.
EDIT:
name := """scheduling-backend"""
version := "1.0"
scalaVersion := "2.10.2"
resolvers += "spray repo" at "http://repo.spray.io"
resolvers += "spray nightlies" at "http://nightlies.spray.io"
resolvers += "SpringSource Milestone Repository" at "http://repo.springsource.org/milestone"
resolvers += "Neo4j Cypher DSL Repository" at "http://m2.neo4j.org/content/repositories/releases"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.3.0",
"com.typesafe.akka" %% "akka-slf4j" % "2.3.0",
"com.typesafe.akka" %% "akka-testkit" % "2.3.0" % "test",
"com.typesafe.akka" %% "akka-persistence-experimental" % "2.3.0",
"io.spray" % "spray-can" % "1.3.0",
"io.spray" % "spray-routing" % "1.3.0",
"io.spray" % "spray-testkit" % "1.3.0" % "test",
"io.spray" %% "spray-json" % "1.2.5",
"ch.qos.logback" % "logback-classic" % "1.0.13",
"org.specs2" %% "specs2" % "1.14" % "test",
"com.novocode" % "junit-interface" % "0.7" % "test->default",
"org.springframework.scala" % "spring-scala" % "1.0.0.M2",
"org.springframework.data" % "spring-data-neo4j" % "3.0.0.RELEASE",
"org.springframework.data" % "spring-data-neo4j-rest" % "3.0.0.RELEASE",
"javax.validation" % "validation-api" % "1.1.0.Final",
"com.github.nscala-time" %% "nscala-time" % "0.8.0",
"org.neo4j" % "neo4j-kernel" % "2.0.1" % "test" classifier "tests",
"com.sun.jersey" % "jersey-core" % "1.9",
"org.mockito" % "mockito-all" % "1.9.5"
)
scalacOptions ++= Seq(
"-unchecked",
"-deprecation",
"-Xlint",
"-Ywarn-dead-code",
"-language:_",
"-target:jvm-1.7",
"-encoding", "UTF-8"
)
testOptions += Tests.Argument(TestFrameworks.JUnit, "-v")