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
197
votes
5 answers

ScalaTest in sbt: is there a way to run a single test without tags?

I know that a single test can be ran by running, in sbt, testOnly *class -- -n Tag Is there a way of telling sbt/scalatest to run a single test without tags? For example: testOnly *class -- -X 2 it would mean "run the second test in the class.…
Nacht
  • 10,488
  • 8
  • 31
  • 39
122
votes
5 answers

What’s the difference between ScalaTest and Scala Specs unit test frameworks?

Both are BDD (Behavior Driven Development) capable unit test frameworks for Scala written in Scala. And Specs is built upon may also involve the ScalaTest framework. But what does Specs offer ScalaTest doesn't? What are the differences?
Alex
  • 8,245
  • 8
  • 46
  • 55
119
votes
6 answers

How to do an instanceof check with Scala(Test)

I'm trying to incorporate ScalaTest into my Java project; replacing all JUnit tests with ScalaTests. At one point, I want to check if Guice's Injector injects the correct type. In Java, I have a test like this: public class InjectorBehaviour { …
helpermethod
  • 59,493
  • 71
  • 188
  • 276
93
votes
3 answers

How to show custom failure messages in ScalaTest?

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…
Udayakumar Rayala
  • 2,264
  • 1
  • 20
  • 17
78
votes
3 answers

Doing something before or after all Scalatest tests

I have a suite of scalatest tests that test different endpoints of a RESTful API. I really want them separated into different files for best organization. My problem is how to start something (an HTTP server in my case, but it doesn't matter what it…
Greg
  • 10,696
  • 22
  • 68
  • 98
61
votes
2 answers

How can I get complete stacktraces for exceptions thrown in tests when using sbt and testng?

The stacktraces are truncated - e.g. they end with [info] ... Using last or changing traceLevel doesn't help - it simply prints the complete stacktrace of the sbt wrapper. This is testing with testng (also I believe using scalatest and sl4j)
wn-
  • 1,475
  • 1
  • 14
  • 14
61
votes
6 answers

ScalaTest: Assert exceptions in failed futures (non-blocking)

import org.scalatest.{ FlatSpec, Matchers, ParallelTestExecution } import org.scalatest.concurrent.ScalaFutures import org.apache.thrift.TApplicationException class Test extends FlatSpec with Matchers with ScalaFutures with ParallelTestExecution { …
flavian
  • 28,161
  • 11
  • 65
  • 105
53
votes
8 answers

How can a private class method be tested in Scala?

I have a companion object with a private method, like so: package com.example.people class Person(val age: Int) object Person { private def transform(p: Person): Person = new Person(p.age + 1) } I would like to test this method, with something…
gdiazc
  • 2,108
  • 4
  • 19
  • 30
52
votes
1 answer

What is the === (triple-equals) operator in Scala Koans?

I started working my way through the Scala Koans, which is organized around a suite of unit tests with blanks that one needs to fill in. (This idea was modeled after a similar Ruby Koans project.) You start the sbt tool running a test, and it…
pohl
  • 3,158
  • 1
  • 30
  • 48
51
votes
2 answers

Comparing collection contents with ScalaTest

I'm trying to unit-test some Scala that is very collection-heavy. These collections are returned as Iterable[T], so I am interested in the contents of the collection, even if the underlying types differ. This is actually two related problems: How…
Michael Koval
  • 8,207
  • 5
  • 42
  • 53
46
votes
4 answers

"Unknown artifact. Not resolved or indexed" error for scalatest

I'm trying to modify the build.sbt file to add scalatest dependencies in IntelliJ IDEA. There's no error log in the console but I got a Unknown artifact. Not resolved or indexed. when I hovered my mouse over the underline. How do I solve this? Many…
user3474606
  • 515
  • 1
  • 6
  • 15
36
votes
2 answers

java.lang.NoClassDefFoundError: scala/Product$class

I am new to scala and I am trying out few sample codes for testing. However I am facing some issues when I run the test code. When I run the test, I am getting an error [trace] Stack trace suppressed: run last test:executeTests for the full…
Amogh Huilgol
  • 1,252
  • 3
  • 18
  • 25
35
votes
3 answers

Scalatest - how to test println

Is there something in Scalatest that will allow me to test the output to the standard out via a println statement? So far I've mainly been using FunSuite with ShouldMatchers. e.g. how do we check the printed output of object Hi { def hello() { …
Luigi Plinge
  • 50,650
  • 20
  • 113
  • 180
34
votes
2 answers

Using the "should NOT produce [exception]" syntax in ScalaTest

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…
Guillaume Belrose
  • 2,478
  • 4
  • 23
  • 24
30
votes
1 answer

In ScalaTest is there any difference between `should`, `can`, `must`

Just started using ScalaTest and I quite like it. By just reading the docs I have thus far been unable to figure out whether there is any substantial difference between the can, should and must clauses for a FlatSpec. In particular, I'm wondering…
Marco Massenzio
  • 2,822
  • 1
  • 25
  • 37
1
2 3
99 100