specs2

How design a Specs2 database test, with interdependent tests?

给你一囗甜甜゛ 提交于 2019-12-06 03:02:11
问题 Is there some preferred way to design a Specs2 test, with lots of tests that depend on the results of previous tests? Below, you'll find my current test suite. I don't like the var s inbetween the test fragments. They're "needed" though, since some tests generate ID numbers that subsequent tests reuses. Should I perhaps store the ID numbers in a Specs2 Context instead, or create a separate Object that holds all mutable state? And place only test fragments in the specification object? Or is

Play2 Framework/Scala/Specs2 - Do different FakeApplications share Singleton objects?

☆樱花仙子☆ 提交于 2019-12-05 22:32:34
I'm quite new to Play2 and Scala. I'm writing a simple application that uses ReactiveMongo plugin. I wrote a simple object to use as DAO object UserDAO { def db: reactivemongo.api.DB = ReactiveMongoPlugin.db def collection: JSONCollection = db.collection[JSONCollection]("users") collection.indexesManager.ensure(Index(List("name" -> IndexType.Ascending), unique = true)) def insert(User): Future[LastError] = { collection.insert(unit) } def findOne(query: JsObject): Future[Option[User]] = { collection.find(query).one[User] } def removeOne(query: JsObject): Future[LastError] = { collection.remove

How can I reduce the number of test cases ScalaCheck generates?

╄→гoц情女王★ 提交于 2019-12-05 19:14:50
I'm trying to solve two ScalaCheck (+ specs2) problems: Is there any way to change the number of cases that ScalaCheck generates? How can I generate strings that contain some Unicode characters? For example, I'd like to generate about 10 random strings that include both alphanumeric and Unicode characters. This code, however, always generates 100 random strings, and they are strictly alpha character based: "make a random string" in { def stringGenerator = Gen.alphaStr.suchThat(_.length < 40) implicit def randomString: Arbitrary[String] = Arbitrary(stringGenerator) "the string" ! prop { (s:

Mockito stubbing method with value class argument fails with NullPointerException

浪尽此生 提交于 2019-12-05 13:49:16
Using typed value classes as IDs is a common pattern in Scala. However, it seems Mockito has an issue when stubbing methods that take value classes as arguments. In the example below, the first stub, with an actual value works just fine, but the second one, that uses an argument matcher throws NullPointerException. The only reference to this I've found is this question but the solution shown there does not work. Anyone knows a solution to this, or a work-around? Versions are: org.mockito:mockito-all:1.10.19 and org.specs2:specs2_2.11:2.4.15 import org.specs2.mutable.Specification import org

Error using Mockito and Specs2

≡放荡痞女 提交于 2019-12-05 11:44:43
I have the following spec: import org.specs2.mock.Mockito import org.specs2.mutable.Specification class LinkUserServiceSpec extends Specification with Mockito { val linkUserService = mock[LinkUserService] "The 'LinkUserService' isUserLinked method" should { "return false when a previously unlinked userId is passed in for a given service" in { linkUserService.isUserLinked("nobody", "YT") returns false linkUserService.isUserLinked("nobody", "YT") must beFalse } } } And the following dependency in my build.sbt: "org.specs2" %% "specs2" % "2.2" % "test" However I get this error when I type test

Seq empty test with specs2

孤街浪徒 提交于 2019-12-05 06:08:24
How can I check if a Seq[String] is empty or not using specs2 in Scala ? I am using seq must be empty or seq.length must be greaterThan(0) but I end up always with type mismatch errors. ret is Seq[String] ret.length must be greaterThan(0) [error] ApiTest.scala:99: type mismatch; [error] found : Int [error] required: org.specs2.matcher.Matcher[String] [error] ret.length must be greaterThan(0) I think the type mismatch error is caused by another bit of code than that which you've posted. Your example should just work with: ret must not be empty I've tried and confirmed to be working correctly:

How to group tests using specs2?

烂漫一生 提交于 2019-12-05 04:23:39
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 when not possible" in { whatever(null).work must beNone } } We can group several Specification of this

How to show custom failure message in Specs2 (Scala)?

天大地大妈咪最大 提交于 2019-12-05 02:39:33
For example, for code like this: myNum must beEqualTo("SOME INTERESTING TEXT") The message will be like the following: java.lang.Exception: ArrayBuffer() doesn't have size 1 but size 0 Is there an elegant way to get customised message displayed here? First you can name value you're testing. myNum aka "meaningful name" must_== expectedValue You can also overwrite the full message. (myNum must_== expectedValue).setMessage("Full failure message") 来源: https://stackoverflow.com/questions/25351312/how-to-show-custom-failure-message-in-specs2-scala

How do I set the test output to console instead of html in gradle for specs2

蹲街弑〆低调 提交于 2019-12-05 02:15:17
I'm using specs2/scala for unit tests and using gradle to build. By default the unit-test output goes to a html file. I would like to have the output go directly to stdout (just like sbt). Anyone know the magic incantation? thanks wing You can use test { //makes the standard streams (err and out) visible at console when running tests testLogging.showStandardStreams = true } But this logs stdout at the info level so you need to run gradle -i to see it (it seems this will be fixed in 1.1: http://issues.gradle.org/browse/GRADLE-1966 ) Alternatively, you can add an event handler: test { onOutput {

How to run specifications sequentially

天大地大妈咪最大 提交于 2019-12-04 16:23:48
问题 I want to create few specifications that interoperate with database. class DocumentSpec extends mutable.Specification with BeforeAfterExample { sequential def before() = {createDB()} def after() = {dropDB()} // examples // ... } Database is created and dropped before and after every example (which is executed sequentially). Everithing works as expected until there is only one spec that works with database. Because specifications are executed parallel, they interfere and fail. I hope that I'm