本文介绍了使用Specs2测试JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了(Inbuilt.sbt)matcher-extra:-

I added(In built.sbt) matcher-extra :-

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

("/"符号无法解析)

the ("/" the symbols are not resolving)

我的Json示例测试用例如下所示:-

My example test case for Json is looking like below:-

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

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

我要来这里了,请给我解决方法

I am strucking here please give me the solution

谢谢

GSY

推荐答案

我终于开始使用它了.

这里有一些有关设置build.sbt文件的说明.向下滚动到页面的最底部. http://etorreborre.github.io/specs2/#Downloads

There are some instructions for setting up your build.sbt file here. Scroll down to the very bottom of the page. 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")

resolvers ++= Seq("snapshots", "releases").map(Resolver.sonatypeRepo)

play.Project.playScalaSettings

这篇关于使用Specs2测试JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 01:16