scalatest

Does Scalatest have any support for assumptions?

旧巷老猫 提交于 2019-12-04 08:02:56
As per the title, I'm wondering if it's possible to provide "assumptions" to Scalatest when defining a particular test case. Assumptions in this context would be preconditions for a test, such that if the assumption evaluated to false, the test would be skipped rather than executed (and handled accordingly by the runners). In this particular case, I'm thinking about dependencies between tests - so there might be a basic test that validates whether a method returns anything at all , followed by later tests that drill into the specifics of the response. If the former test fails, I'd rather have

How to show custom failure messages in ScalaTest?

 ̄綄美尐妖づ 提交于 2019-12-04 07:48:53
问题 Does anyone know how to show a custom failure message in ScalaTest? For example: NumberOfElements() should equal (5) Shows the following message when it fails: 10 did not equal 5 But i want more descriptive message like: NumberOfElements should be 5. 回答1: You're the first to ask for such a feature. One way to achieve this is with withClue. Something like: withClue("NumberOfElements: ") { NumberOfElements() should be (5) } That should get you this error message: NumberOfElements: 10 was not

sbt: Add dependency on scalatest library. Where?

丶灬走出姿态 提交于 2019-12-04 07:40:41
I created a scala project using SBT and wrote some unit test cases using scalatest. But somehow sbt test can't find the org.scalatest package. Here my project definition files: Sources are in src/main/scala respective src/test/scala build.sbt : name := "MyProject" version := "0.1" scalaVersion := "2.9.2" project/plugins.sbt : addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0") project/build.sbt : libraryDependencies += "org.scalatest" %% "scalatest" % "1.8" % "test" I'm using SBT 0.11.3. Compiling the program using sbt compile on the console works fine. Furthermore I found

ScalaTest Run Configuration in Eclipse: cannot find Suite Class

萝らか妹 提交于 2019-12-04 05:24:39
Problem: I cannot setup Run Configurations to run scalatest for the Scalatests in my project. Steps to reproduce: Right click on Scala Suite and click on Run as -> Run configurations.. On the left, I see a configuration template for ScalaTest. I click on New and fill the Name but it cannot find the suite-class. Note: It is mentioned here that I should see Run as -> ScalaTest - Suite but I do not see that option. I tried using context menu in the editor, and in the package explorer Steps taken: Using: Scala IDE for Eclipse version: 2.1.0.m3-2_09 Using SBT, assemble project, run eclipse command

How to use ScalaTest “contain allOf” on two lists?

笑着哭i 提交于 2019-12-04 02:59:47
问题 I was looking for a ScalaTest matcher to check that a list contains all of the needed elements (given within another list), but that may also be others. contain allOf demands to get two fixed elements, for some reason, the rest as varargs. I can do a workaround like this, but it's tremendously ugly: val list = List(1,2,3,4) val wanted = List(1,2,3) list should contain allOf ( wanted.head, wanted.tail.head, wanted.tail.tail :_* ) // ugly workaround For giving a list as the match, there is

Using JUnit @Rule with ScalaTest (e.g. TemporaryFolder)

我的未来我决定 提交于 2019-12-04 02:59:20
问题 I would like to be able to use JUnit rules such as TemporaryFolder or other TestRule s we have already developed in-house. What is the best method to accomplish that? I'm aware of JUnitSuite but it doesn't seem to pick up the @Rule annotation. I would like to use a different ScalaTest suite anyway. So my questions are: Are JUnit rules supported by a ScalaTest suit? If not, is there a library out there which would make using Junit TestRule s possible? If not, how to use JUnit TestRule s in

can you test nested functions in scala?

谁都会走 提交于 2019-12-04 02:18:40
Is there any way to test a nested function (ideally with ScalaTest)? For example, is there a way to test g() in the below code: def f() = { def g() = "a string!" g() + "– says g" } g is not visible outside of f , so I daresay no, at least not without reflection. I think testing g would break the concept of unit testing, anyway, because you should never test implementation details but only public API behaviour. Tracking an error to a mistake in g is part of the debugging process if tests for f fail. If testing g is important for you, define g as (protected) method outside of f . That might

Failing a scalatest when akka actor throws exception outside of the test thread

不问归期 提交于 2019-12-04 01:28:38
问题 I've had a situation come up and bite me a few times where I'm testing an Actor and the Actor throws an exception unexpectedly (due to a bug), but the test still passes. Now most of the time the exception in the Actor means that whatever the test is verifying won't come out properly so it the test fails, but in rare cases that's not true. The exception occurs in a different thread than the test runner so the test runner knows nothing about it. One example is when I'm using a mock to verify

java.lang.IncompatibleClassChangeError: Implementing class with ScalaCheck and ScalaTest

女生的网名这么多〃 提交于 2019-12-03 23:23:23
问题 I'm facing a nasty exception when trying to write a test using ScalaCheck and ScalaTest. Here's my dependencies: libraryDependencies ++= Seq( "org.scalatest" %% "scalatest" % "2.2.6" % "test", "org.scalacheck" %% "scalacheck" % "1.13.0" % "test" ) Here's my test: import org.scalatest.PropSpec import org.scalatest.prop.Checkers class MyPropSpec extends PropSpec with Checkers { property("List.concat") { check((a: List[Int], b: List[Int]) => a.size + b.size == (a ::: b).size) } } When I try to

Using the “should NOT produce [exception]” syntax in ScalaTest

╄→尐↘猪︶ㄣ 提交于 2019-12-03 22:12:21
I'am toying with Specs2 and ScalaTest for BDD in Scala. I've written expectations in Specs2 when I am asserting that a given exception should not be thrown. "do something" in { { .... } must not(throwA[MyException]) } I was hoping to be able to write the equivalent in ScalaTest like: "do something" in { evaluating { .... } should not produce[MyException] } But this does not compile and I could not find way of doing it. Is that even possible? Many thanks in advance. This is not possible directly in the latest version of ScalaTest because the method should of EvaluatingApplicationShouldWrapper