2013-12-11 72 views
3

測試JSON數據I中加入(在built.sbt)匹配-額外: -使用Specs2

"org.specs2"    %% "specs2"   % "2.3.4"     % "test", 
"org.specs2"    % "specs2-matcher-extra_2.10" % "2.3-scalaz-7.1.0-M3", 

的( 「/」 符號未解決)

我的例子測試用例JSON是看着象下面這樣: -

package specs.model 
import org.specs2.mutable.Specification 
import org.specs2.matcher.JsonMatchers 

class Json extends Specification with JsonMatchers { 

"Json Matcher" should { 
"1st field" in { 
    val json = """{"name":"sagar"}""" 
    json must /("name" -> "sagar") 
} 
"2nd field" in { 
    val json = """{"id":1}""" 
    json must /("id" -> 1.0) 
} 
} 
} 

ERRORMSG: -

[info] Compiling 2 Scala sources to \target\scala- 2.10\test-classes... 
[info] Json 
[info] 
[info] Json Matcher should 
[info] + 1st field 
[info] + 2nd field 
[info] 
[info] Total for specification Json 
[info] Finished in 76 ms 
[info] 2 examples, 0 failure, 0 error 
[trace] Stack trace suppressed: run 'last specBuilder/test:test' for the full output. 
[error] Could not run test specs.model.Json: java.lang.NoSuchMethodError:  scalaz.Scalaz$.tuple2Monoid(Lscalaz/Monoid;Lscalaz/Monoid;)Lscalaz/std/Tuple2Monoid; 
[error] Error: Total 0, Failed 0, Errors 0, Passed 0, Skipped 0 
[error] Error during tests: 
[error] specs.model.Json 
[error] (specBuilder/test:test) sbt.TestsFailedException: Tests unsuccessful 
[error] Total time: 9 s, completed 11 Dec, 2013 5:12:39 PM 

我在這裏strucking請給我解決

感謝,

GSY

+0

你在你的SBT有scalaz嗎?看起來像依賴可能會丟失。您可以嘗試添加:[''org.scalaz「%%」scalaz-core「%」7.0.5「'](https://github.com/scalaz/scalaz) – jcern

+0

已添加,但同樣錯誤正在提交 – sagar

+0

我添加了(「/」不解析): - 「org.specs2」%%「specs2」%「2.3.4」%「test」, 「org.specs2」%%「specs2-matcher-extra」%「2.3 .4「%」test「, 」org.scalaz「%%」scalaz-core「%」7.0.4「%」test「, 」org.scalaz「%%」scalaz-concurrent「%」7.0.4 「%」test「, – sagar

回答

5

我終於得到它的工作。

這裏有一些設置build.sbt文件的說明。向下滾動到頁面的最底部。 http://etorreborre.github.io/specs2/#Downloads

我Application.spec文件導入命令:

import org.specs2.mutable._ 
import org.specs2.mutable.Specification 
import org.specs2.matcher.JsonMatchers 
import org.specs2.runner._ 

class yourClass extends Specification with JsonMatchers { } 

以下JAR文件安裝在lib目錄

specs2_2.10-2.3.7-javadoc.jar 
scalaz-core_2.10-7.0.4-javadoc.jar 
scalaz-concurrent_2.10-7.0.4-javadoc.jar 

這是內容我的build.sbt文件。

name := "playExperiments" 

version := "1.0-SNAPSHOT" 

libraryDependencies ++= Seq(
    "org.specs2" %% "specs2" % "2.3.7" % "test", 
    jdbc, 
    anorm, 
    cache 
)  

scalacOptions in Test ++= Seq("-Yrangepos") 

解析器++ = SEQ( 「快照」, 「發行」)。圖(Resolver.sonatypeRepo)

play.Project.playScalaSettings