Testing json data using Specs2

落花浮王杯 提交于 2021-02-09 18:37:28

问题


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)

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

 [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

Thanks,

GSY


回答1:


I finally got it to work.

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

The import commands in my Application.spec file are:

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

class yourClass extends Specification with JsonMatchers {  }

The following jar files are installed in the lib directory

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  

This is the contents of my build.sbt file.

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


来源:https://stackoverflow.com/questions/20518862/testing-json-data-using-specs2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!