specs2


Make ScalaCheck tests deterministic

这一生的挚爱 提交于 2020-01-12 01:45:08
问题 I would like to make my ScalaCheck property tests in my specs2 test suite deterministic, temporarily, to ease debugging. Right now, different values could be generated each time I re-run the test suite, which makes debugging frustrating, because you don't know if a change in observed behaviour is caused by your code changes, or just by different data being generated. How can I do this? Is there an official way to set the random seed used by ScalaCheck? I'm using sbt to run the test suite.

Specs2 - How to define complex objects for Given/When/Then steps

和自甴很熟 提交于 2020-01-06 07:57:23
问题 Specs2's documentation and samples show some codes about the use of Given/Then/When style in an acceptance test. Here one of them: "A given-when-then example for the addition" ^ "Given the following number: ${1}" ^ number1 ^ "And a second number: ${2}" ^ number2 ^ "And a third number: ${3}" ^ number3 val number1: Given[Int] = (_:String).toInt val number2: When[Int, (Int, Int)] = (n1: Int) => (s: String) => (n1, s.toInt) val number3: When[Seq[Int], Seq[Int]] = (numbers: Seq[Int]) => (s: String

Specs2 - How to define complex objects for Given/When/Then steps

笑着哭i 提交于 2020-01-06 07:56:06
问题 Specs2's documentation and samples show some codes about the use of Given/Then/When style in an acceptance test. Here one of them: "A given-when-then example for the addition" ^ "Given the following number: ${1}" ^ number1 ^ "And a second number: ${2}" ^ number2 ^ "And a third number: ${3}" ^ number3 val number1: Given[Int] = (_:String).toInt val number2: When[Int, (Int, Int)] = (n1: Int) => (s: String) => (n1, s.toInt) val number3: When[Seq[Int], Seq[Int]] = (numbers: Seq[Int]) => (s: String

How to group tests using specs2?

风流意气都作罢 提交于 2020-01-02 02:01:06
问题 I'm used to JUnit, in JUnit it is possible to group several tests (usually related to a class) just by defining these tests in a single file (class) and annotating them with @Test . Then, to run several of these tests, a TestSuite is created with @Suite.SuiteClasses and so on. In specs2 it is possible to group several tests at two different levels extending some Specification . For example: "Whatever" should { "do its job when possible" in { whatever(new Thing).work must beSome } "return none

how to make scalatest generate html report through sbt

你。 提交于 2020-01-01 02:51:12
问题 The way to do this for specs2 based test in sbt is (testOptions in Test) += Tests.Argument(TestFrameworks.Specs2, "html") but how about scalatest? I've done lots of Google search, but cannot find a good explanation/solution. 回答1: so two things I need to do... I. use any scalatest artifact after 2.0.M5b. For me, I added this dependency, org.scalatest" %% "scalatest" % "2.0.M6" % "test->*" excludeAll ( ExclusionRule(organization="org.junit", name="junit") ) "test->*" is necessary, otherwise

What is the difference between should and must in scala testing? [duplicate]

五迷三道 提交于 2019-12-25 06:28:04
问题 This question already has an answer here : In ScalaTest is there any difference between `should`, `can`, `must` (1 answer) Closed 3 years ago . Both scalatest and Specs2 have separate matchers for should and must . However, I cannot find any explanation for why you would use one or the other. What exactly is the difference? 回答1: There is no difference, this is purely a syntactic preference. I personally prefer to use must in specs2 because I think that should can make people think that an

Specs2 wrap unit test in database transaction

独自空忆成欢 提交于 2019-12-25 04:17:27
问题 I'm updating my application from Specs2 2.3.12 to 3.6.1 and am having trouble updating the class which wraps our unit tests in a transaction. The 2.3.12 class: class DbTx extends AroundOutside[Session] { var session: Option[Session] = None def around[T : AsResult](t: => T) = { Db.withTransaction { implicit s => session = Some(s) val result = AsResult(t) s.rollback() result } } def outside: Session = session.get } its usage: "my unit test" in (new DbTx).apply { implicit session: Session => ...

How to Test a Play Application that extends a custom trait

99封情书 提交于 2019-12-25 04:11:25
问题 I'm having trouble writing tests for a mixin to my Play application that runs in it's own thread separate from play. I've tried over-writing WithApplication.provideApplication method with no luck. I get an inheriting conflicting methods error. (one from the real app "MyRunnableSystemWrapper", one from my mocked fake mixin called "MyMockedSystemWrapper"). execute(system) runs my system that is tested elsewhere and has sideaffects (connects to networked services, thus failing this test when

Scala specs2 mocking a trait method returns always Nullpointer exception

浪子不回头ぞ 提交于 2019-12-23 20:36:01
问题 I have a trait that I want to mock and use that mocked Trait in another Service during testing. The problem is, that I receive a Nullpointerexception when I try to mock the return value of the indexDocuments function. Testmethod: "createDemand must return None if writing to es fails" in new WithApplication { val demandDraft = DemandDraft(UserId("1"), "socken bekleidung wolle", Location(Longitude(52.468562), Latitude(13.534212)), Distance(30), Price(25.0), Price(77.0)) val es = mock

How can i skip a test in specs2 without matchers?

老子叫甜甜 提交于 2019-12-23 09:07:01
问题 I am trying to test some db dependent stuff with specs2 in scala. The goal is to test for "db running" and then execute the test. I figured out that i can use orSkip from the Matcher class if the db is down. The problem is, that i am getting output for the one matching condition (as PASSED) and the example is marked as SKIPPED. What i want instead: Only execute one test that is marked as "SKIPPED" in case the test db is offline. And here is the code for my "TestKit" package net.mycode.testkit

工具导航Map