Reputation: 6264
I am new to playframework. I am trying to run a unit test. This is my OneTimeTestSuite
file. Here is the code in it.
package com.sentrana.mmcore.test
import org.scalatest.{ DoNotDiscover, Suites }
import org.scalatestplus.play.OneAppPerSuite
import play.api.test.FakeApplication
import com.sentrana.mmcore.controllers.MetaDataSpec
import com.sentrana.Global
class OneTimeTestSuite extends Suites(
new MetaDataSpec
) with OneAppPerSuite {
implicit override lazy val app: FakeApplication =
FakeApplication(withGlobal = Some(Global), additionalConfiguration = Map(
"ConfigSubFolderLocation" -> "/conf/"
))
}
Here is the code in MeteDataSpec
file.
package com.sentrana.mmcore.controllers
import play.api.Play
import play.api.Play.current
import org.joda.time.DateTime
import org.scalatestplus.play.{ PlaySpec, ConfiguredApp }
import play.api.libs.json.{ JsValue, Json }
import play.api.mvc.Cookie
import play.api.test.FakeRequest
import play.api.test.Helpers._
import org.json4s.native.Serialization._
import play.api.test._
class MetaDataSpec extends PlaySpec with ConfiguredApp {
"GetCustomers" should {
"get all the customers" in {
val response = route(FakeRequest(GET, "/api/shop/v0.1/metadata/customers")).get
}
}
}
I am using scalatestplus
.
This is the command I am running for testing.
test-only com.sentrana.mmcore.test.OneTimeTestSuite
This is error I am getting
java.lang.NoSuchMethodError: play.core.Router$HandlerDef.<init>(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;Lscala/collection/Seq;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
Here is my build.sbt file.
name := "MMCorePlatform"
version := "0.1"
scalaVersion := "2.11.4"
resolvers += "softprops-maven" at "http://dl.bintray.com/content/softprops/maven"
libraryDependencies ++= Seq(
"org.scalatestplus" %% "play" % "1.2.0" % "test",
"mysql" % "mysql-connector-java" % "5.1.28",
"postgresql" % "postgresql" % "9.1-901-1.jdbc4",
"org.mongodb" %% "casbah" % "2.8.0",
"org.json4s" %% "json4s-native" % "3.2.10",
"org.json4s" % "json4s-mongo_2.10" % "3.2.10",
"org.json4s" % "json4s-ext_2.10" % "3.2.10",
"com.typesafe" %% "play-plugins-mailer" % "2.1-RC2",
"com.typesafe" %% "scalalogging-slf4j" % "1.0.1",
"org.squeryl" %% "squeryl" % "0.9.5-6",
"com.amazonaws" % "aws-java-sdk" % "1.9.31",
"me.lessis" %% "courier" % "0.1.3",
"com.typesafe.akka" %% "akka-remote" % "2.2.3", // very important : Need to synchronize akka-remote version with play version, otherwise wierd error might occur
filters,
jdbc,
anorm,
cache
)
dependencyOverrides += "com.google.guava" % "guava" % "15.0"
//Adds separate configuration file for test configuration
javaOptions in Test += "-Dconfig.file=conf/test.conf"
//Note, a separate integration test configuration that can be invoked using "int:test" has been created in project/Build.scala.
//Adds separate configuration file for integration test configuration
javaOptions in IntTest += "-Dconfig.file=conf/int-test.conf"
//Adds "clRun" task to allow use of simple command line application to test application
val clRun = TaskKey[Unit]("clRun","Run task for command line application")
//Adds an additional resource directory used to read the file based meta-data repository
unmanagedResourceDirectories in Compile += baseDirectory.value / "app/resources"
//Adds command line run task
fullRunTask(clRun, Compile, "com.sentrana.mmcore.commandline.TaskPlannerCommandLine", null)
play.Project.playScalaSettings
scalacOptions in (Compile,doc) := Seq("-groups", "-implicits")
//Sets ScalaTest tests to output junit xml format test output
testOptions in Test <+= (target in Test) map {
t => Tests.Argument(TestFrameworks.ScalaTest, "-u", "%s" format (t / "test-reports"))
}
//Sets Specs2 tests to output junit xml format test output
testOptions in IntTest += Tests.Argument(TestFrameworks.Specs2, "junitxml")
//Publishing configurations
publishTo := {
val nexus = "http://10.46.8.121:8081/nexus/"
if (version.value.trim.endsWith("SNAPSHOT"))
Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some("releases" at nexus + "content/repositories/releases")
}
publishMavenStyle := true
// Credentials for publishing to our internal repository
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")
I hope I have made my question clear. If there is any confusion, please ask. Thanks in advance.
Upvotes: 1
Views: 435
Reputation: 37461
Your project is marked as scala 2.11 but you're using json4s at 2.10. Scala does not have binary compatibility between major versions.
Change your dependency to something like
"org.json4s" %% "json4s-mongo" % "3.2.10",
"org.json4s" %% "json4s-ext" % "3.2.10",
The %%
automatically adds the scala version suffix to the artifact name, which is the convention for scala
Upvotes: 1