2015-05-11 25 views
1

我是新玩法框架。我正在嘗試運行單元測試。這是我的OneTimeTestSuite文件。這裏是它的代碼。無法在scala playframework上運行單元測試

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/" 
    )) 
} 

這裏是MeteDataSpec文件中的代碼。

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 
    } 
    } 
} 

我正在使用scalatestplus

這是我正在運行的測試命令。

test-only com.sentrana.mmcore.test.OneTimeTestSuite

這是錯誤我得到

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

這是我build.sbt文件。

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") 

我希望我已經明確提出了我的問題。如果有任何混淆,請詢問。提前致謝。

+0

您可以將您的build.sbt?當我在構建中導致混合scala版本的依賴項時,我看到了類似的錯誤。 – Daenyth

回答

0

您的項目被標記爲scala 2.11,但您使用的是2.10的json4s。 Scala在主要版本之間沒有二進制兼容性。

更改依賴於像

"org.json4s" %% "json4s-mongo" % "3.2.10", 
"org.json4s" %% "json4s-ext" % "3.2.10", 

%%自動添加斯卡拉版本爲後綴的神器的名字,這是斯卡拉公約

相關問題