Questions tagged [scalatest]

The Scala testing framework

ScalaTest is a testing framework for Scala, which can test either Scala or Java code.

It supports a number of different testing styles, as JUnit, TestNG, FunSuite (For test-driven development), Spec (for behaviour driven development) and FeatureSpec (for functional, integration, or acceptance testing).

1597 questions
15
votes
1 answer

Why is my Scalacheck/Scalatest PropertyCheckConfig being ignored?

I have a project with a lot of Scalacheck generators that is getting a GeneratorDrivenPropertyCheckFailedException with the message "Gave up after 0 successful property evaluations. 2 evaluations were discarded." I want to have it try to evaluate it…
myyk
  • 1,537
  • 1
  • 15
  • 35
15
votes
2 answers

Run just a specific scalatest test from sbt

sbt's test-only command can be used to run the tests found in a specific test class. With JUnit tests you can use test-only to run specific methods on a test class e.g. test-only mypackage.MyTestClass.test1Equals1 to run just that method. Is such a…
adamnfish
  • 10,935
  • 4
  • 31
  • 40
15
votes
2 answers

A comparison of ScalaTest and Spock

How do scalatest and spock differ? what is the added-value of each ? Which is more agile for Behavior Driven Development (BDD)? Please could you share some thoughts on the matter ? I want to start BDD, I want to pick one between the two, therefore…
MaatDeamon
  • 9,532
  • 9
  • 60
  • 127
15
votes
1 answer

Run ScalaTest tests in parallel

Given the following test suite: class ParallelizeMe extends FunSuite with BeforeAndAfterAll { override def beforeAll() = println("before") override def afterAll() = println("after") test("test 1") { …
earldouglas
  • 13,265
  • 5
  • 41
  • 50
14
votes
2 answers

Why does scalatest mix up the output?

I run my scalatest from sbt, and the output gets mixed up - scalatest prints all the test run, and comments to them, and somewhere in the middle it prints the statistics: > test [info] Compiling 1 Scala source to…
Rogach
  • 26,050
  • 21
  • 93
  • 172
14
votes
1 answer

How to disable "Slow" tagged Scalatests by default, allow execution with option?

I want to disable certain automated tests tagged as "Slow" by default but allow the user to enable their execution with a simple command line. I imagine this is a very common use case. Given this test suite: import org.scalatest.FunSuite import…
clay
  • 18,138
  • 28
  • 107
  • 192
14
votes
1 answer

How to run all scalatest of a multi-modules sbt with intellij?

I can run: a specific scala test either by right clicking on the test and choose run or if I have run it once previously, by selecting the test in run menu > run... I can run all junit tests by making a new run/debug configuration > + > junit >…
Juh_
  • 14,628
  • 8
  • 59
  • 92
14
votes
2 answers

How to override guice modules in Playframework unit tests using ScalaTest

I want to write functional test for my controller in PlayFramework. To do that I want to mock implementation of some classes. I found nice example of how to do that using spec2 here:…
Zygimantas Gatelis
  • 1,923
  • 2
  • 18
  • 27
14
votes
1 answer

ScalaTest - check for "almost equal" for floats and objects containing floats

While writing tests for operations with floats or objects containing floats (like vectors or matrices), I often want to test not for equality, but for "almost equal" (difference allowed to be some epsilon). When using ScalaTest FunSuite, one…
Suma
  • 33,181
  • 16
  • 123
  • 191
14
votes
3 answers

How to get intellij to offer a text diff comparison on failed tests

I'm writing a Scala test with some ScalaTest matchers. When my test fails, intellij says something like…
Bruce Lowe
  • 6,063
  • 1
  • 36
  • 47
14
votes
2 answers

Concise way to assert a value matches a given pattern in ScalaTest

Is there a nice way to check that a pattern match succeeds in ScalaTest? An option is given in scalatest-users mailing list: match { case => case obj => fail("Did not match: " + obj) } However, it doesn't compose (e.g. if I…
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
14
votes
4 answers

Unit testing several implementation of the same trait/interface

I program mostly in scala and java, using scalatest in scala and junit for unit testing. I would like to apply the very same tests to several implementations of the same interface/trait. The idea is to verify that the interface contract is enforced…
paradigmatic
  • 40,153
  • 18
  • 88
  • 147
14
votes
4 answers

BDD in Scala - Does it have to be ugly?

I've used lettuce for python in the past. It is a simple BDD framework where specs are written in an external plain text file. Implementation uses regex to identify each step, proving reusable code for each sentence in the specification. Using…
tiagoboldt
  • 2,426
  • 1
  • 24
  • 30
13
votes
1 answer

Scalatest: waiting for an assertion to become true

Is there anything that exists in scalatest that will wait for a period of time for an assertion to become true? So, for example, if I have a thread that computes something asynchronously, I want to wait in my test for the computation to equal the…
Neil
  • 1,754
  • 2
  • 17
  • 30
13
votes
2 answers

How to prevent sbt from running integration tests?

Maven surefire-plugin doesn't run integration tests (they named with "IT" suffix by convention), but sbt runs both: unit and integration. So, how to prevent this behaviour? Is there a common way to distinguish integration and unit tests for…
dk14
  • 22,206
  • 4
  • 51
  • 88