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
9
votes
1 answer

How to get a list of defined tests in sbt project in sbt 0.12?

How to get a list of test cases (fully qualified names) under current project? The environment is Scala 2.10.2, Sbt 0.12.3 and scalatest 1.9.1
user972946
9
votes
3 answers

Intellij will not run ScalaTests - "Incompatible Class Change Error"

I'm trying to run tests for an sbt-based Scala application in intellij. But I get the following error which I'm not sure how to fix: Testing started at 21:07 ... java.lang.IncompatibleClassChangeError: Found class scala.collection.mutable.ArrayOps,…
Nick
  • 1,845
  • 3
  • 15
  • 22
9
votes
1 answer

Field inside object which extends App trait is set to null. Why is that so?

I'm trying to use scalatest to test an App like this: object Main extends App { val name = "Greg" } class JunkTests extends FunSpec with MustMatchers { describe("Junk Tests") { it("Junk-1 -- Must do stuff") { …
Greg
  • 10,696
  • 22
  • 68
  • 98
9
votes
2 answers

Getting started with Scala, Scalatest, and Maven

I created a new scala project with the following: mvn org.apache.maven.plugins:maven-archetype-plugin:2.2:generate -DarchetypeGroupId=org.scala-tools.archetypes -DarchetypeArtifactId=scala-archetype-simple -DarchetypeVersion=1.3 …
MrDrews
  • 2,139
  • 2
  • 22
  • 22
9
votes
1 answer

Excluding a ScalaTest test when calling my tests from within sbt

I want to write a test that calls a remote server and validates the response because the server may change (it's not under my control). To do this I figure I'd give it a tag (RemoteTest) and then exclude it when calling the runner: sbt> test-only *…
pr1001
  • 21,727
  • 17
  • 79
  • 125
8
votes
2 answers

In scalatest, how to show full diff in test result?

When there is an equality assertion in scalatest that fails. It generally shows only the different part, e.g.: "...error; !I e: F[Arg] [g invalid because nonconformant bounds; [Arg, Nothing] [A <:…
tribbloid
  • 4,026
  • 14
  • 64
  • 103
8
votes
1 answer

How can I get a return value from ScalaTest indicating test suite failure?

I'm running a ScalaTest (FlatSpec) suite programmatically, like so: new MyAwesomeSpec().execute() Is there some way I can figure out if all tests passed? Suite#execute() returns Unit here, so does not help. Ideally, I'd like to run the whole suite…
Sasgorilla
  • 2,403
  • 2
  • 29
  • 56
8
votes
2 answers

SBT / ScalaTest: Configurations already specified for module

After cloning an SBT repo and trying to launch SBT shell inside the directory, I'm getting the following error java.lang.IllegalArgumentException: requirement failed: Configurations already specified for module…
y2k-shubham
  • 10,183
  • 11
  • 55
  • 131
8
votes
3 answers

Async before and after for creating and dropping scala slick tables in scalatest

I'm trying to figure out a way to have async before and after statements where the next test cases aren't run until the completion of the action inside of the test case. In my case, it is the creating and dropping a table inside of a database val…
Chris Stewart
  • 1,641
  • 2
  • 28
  • 60
8
votes
1 answer

How to use the logical 'OR' operator with "should be" in scala?

I was trying to use the "should be" function along with the logical "OR" operator as follows (for example) : def String(x :Integer) :Integer ={ /*---------------- -----------------*/ return value; } String.value.size should be…
Goldengirl
  • 957
  • 4
  • 10
  • 30
8
votes
4 answers

Passing additional arguments to tests with ScalaTest

Currently I'm using IntelliJ Idea 15 and Scalatest framework to make some unit tests. And I need to pass my own arguments into test and somehow read them from code. For instance: Suppose I have such class class Test extends FunSuite { test("Some…
alex
  • 942
  • 1
  • 10
  • 26
8
votes
1 answer

How to make scalatest matcher to ignore white-spaces when compare two strings?

I have the following test "Matchers" should "ignore whitespace if configured so" in { " aaa \n \n\r bbb".replaceAll("\\s+", " ") shouldBe "\naaa bbb".replaceAll("\\s+", " ") } There is a scalatest idiomatic way to do this?
raisercostin
  • 8,777
  • 5
  • 67
  • 76
8
votes
3 answers

Disable scalatest logging statements when running tests from maven

What is the method to disable logging on the scalatest log4j messages: The log4j.properties is as follows: log4j.rootLogger=INFO,CA,FA #Console…
WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560
8
votes
2 answers

Scalatest: how to check if a collection contains element that satisfies certain criteria

Say I have a list of books: val books = List( Book(title="Foo", year=2014), Book(title="Bar", year=2014)) How to check with a single expression if collection books is not empty and only contains books published in 2014?
Alex Vayda
  • 6,154
  • 5
  • 34
  • 50
8
votes
2 answers

How to only show stdout of a scalatest test if it fails

With the junit-interface runner, there was this handy option: -q Suppress stdout for successful tests. Stderr is printed to the console normally. Stdout is written to a buffer and discarded when a test succeeds. If it fails, the…
Mysterious Dan
  • 1,316
  • 10
  • 25