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
12
votes
3 answers

Scalatest or specs2 with multiple test cases

In TestNg and Java, we can run multiple test cases using DataProvider, and this runs as separate tests, meaning execution of a test isn't stopped on failure. Is there an analogue for ScalaTest or Specs/Specs2?
user44242
  • 1,168
  • 7
  • 20
12
votes
1 answer

FunSuite missing even though ScalaTest is imported

I want to start writing simple tests in Scala using ScalaTest. But for some reason, I can access org.scalatest but not org.scalatest.FunSuite This is what my build.sbt looks like: name := "Algorithms" version := "0.1" scalaVersion :=…
Varun Gawande
  • 870
  • 9
  • 21
12
votes
3 answers

How to mock a function within Scala object using Mockito?

I am really new to Scala. I tried to mock a simple Scala function using Mockito, but I get the following error. I have checked the internet but I was unable to find out the error. object TempScalaService { def login(userName: String, password:…
Dilan
  • 1,389
  • 5
  • 14
  • 24
12
votes
2 answers

Setting environment variables when running Scala / SBT test suite

I've created a Config object with a get method to return different strings based on the PROJECT_ENV environment variable. If PROJECT_ENV=test, then Config.get("somePath") returns some/path.csv, otherwise it returns…
Powers
  • 18,150
  • 10
  • 103
  • 108
12
votes
1 answer

PowerMockito throwing ClassNotPreparedException even with @PrepareForTest using Scala Test

I have the following test... import org.scalatest.junit.JUnitRunner ... @PowerMockRunnerDelegate(classOf[JUnitRunner]) @PrepareForTest(Array(classOf[AuditLog])) class ConnectorAPITest extends path.FreeSpec with ShouldMatchers { "Mocked Tests" - { …
Jackie
  • 21,969
  • 32
  • 147
  • 289
12
votes
1 answer

not found: value assertThrows

I have the following test class: import org.scalatest.FunSuite @RunWith(classOf[JUnitRunner]) class NodeScalaSuite extends FunSuite { With this test method: test("Now doesn't terminate future that's not done") { val testFuture: Future[Int] =…
bsky
  • 19,326
  • 49
  • 155
  • 270
12
votes
1 answer

ScalaTest DeferredAbortedSuite error when running simple tests.

My original code had a lot more going on, which distracted me from the true cause of the problem. This captures the essential problem. import org.scalatest.AsyncFlatSpec import scala.concurrent.Future class AsyncFlatSpecSpec extends…
Bill Frasure
  • 859
  • 8
  • 19
12
votes
2 answers

ScalaTest thrownBy testing exception message

To test if my code is throwing expected exception I use the following syntax: an [IllegalArgumentException] should be thrownBy(Algorithms.create(degree)) is there any way to test if thrown exception contains expected message like: an…
Łukasz Rzeszotarski
  • 5,791
  • 6
  • 37
  • 68
12
votes
1 answer

ScalaTest on sbt not running any tests

I am trying to run my tests with: sbt and then test. My build.sbt looks like this lazy val scalatest = "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test" lazy val root = (project in file(".")). settings( name := "highlight2pdf", version…
FabioCosta
  • 3,069
  • 6
  • 28
  • 50
12
votes
3 answers

How to use ScalaTest "contain allOf" on two lists?

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…
akauppi
  • 17,018
  • 15
  • 95
  • 120
12
votes
1 answer

Scalacheck won't properly report the failing case

I've wrote the following spec "An IP4 address" should "belong to just one class" in { val addrs = for { a <- Gen.choose(0, 255) b <- Gen.choose(0, 255) c <- Gen.choose(0, 255) d <- Gen.choose(0, 255) } yield…
12
votes
1 answer

Scala testing mocking implicit parameters?

I'm having a bit of a tough time trying to understand how to write tests in Scala when implicit parameters are involved. I have the following (short version) of my code and test: Implementation (Scala 2.10, Spray and Akka): import…
C0deAttack
  • 24,419
  • 18
  • 73
  • 81
12
votes
5 answers

Access ScalaTest test name from inside test?

Is it possible to access the name of the currently executing test, from within a ScalaTest test? (And how would I do it?) Background: I'm testing that my Data Access Object eventually throws an OverQuotaException if a user e.g. creates too many…
KajMagnus
  • 11,308
  • 15
  • 79
  • 127
12
votes
2 answers

How to use just one scala library for maven/eclipse/scala

I have configured a project to use scala/maven/Eclipse. Because I need a scala library on the build path and scalatest also uses its own scala library I receive this warning : More than one scala library found in the build path, all with …
blue-sky
  • 51,962
  • 152
  • 427
  • 752
12
votes
3 answers

How do I get Scalatest into Eclipse?

I have the Typesafe stack installed, including ScalaTest for Scala IDE 0.9.3. I cannot figure out how to attach it to a new project. I have other projects (from the Coursera Scala course that I just took) that use it, but I cannot use it in a new…
David Matuszek
  • 1,263
  • 1
  • 16
  • 30