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

org.scalatest: Global setup (like beforeAllSuites?)

I have a scala application with some test using org.scalatest. These test need some global setup (and teardown), in order to manage the test database. Please don't tell me my tests should not hit the database and I should do it the…
11
votes
3 answers

How To Create Temporary Directory in Scala Unit Tests

In scala how can a unit test create a temporary directory to use as part of the testing? I am trying to unit test a class which depends on a directory class UsesDirectory(directory : java.io.File) { ... } I'm looking for something of the…
Ramón J Romero y Vigil
  • 17,373
  • 7
  • 77
  • 125
11
votes
3 answers

Testing multiple data sets with ScalaTest

is there any convenient way execute tests on multiple data sets - like in JUnit's parametrized tests?
Jarek
  • 7,425
  • 15
  • 62
  • 89
11
votes
1 answer

Mock Java static class from scala

Any idea how from ScalaTest I can mock a static Java class?? I have this code val mockMapperComponent: IMapperComponent = mock[IMapperComponent] val applicationContext: ApplicationContext = mock[ApplicationContext] val appContextUtil:…
paul
  • 12,873
  • 23
  • 91
  • 153
11
votes
3 answers

How to test for additional properties of expected Exceptions using ScalaTest

I'm using ScalaTest for testing some Scala code. I currently testing for expected exceptions with code like this import org.scalatest._ import org.scalatest.matchers.ShouldMatchers class ImageComparisonTest extends FeatureSpec with…
Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
11
votes
2 answers

Scalatest and Spark giving "java.io.NotSerializableException: org.scalatest.Assertions$AssertionsHelper"

I’m testing a Spark Streaming application with the help of "com.holdenkarau.spark-testing-base" and scalatest. import com.holdenkarau.spark.testing.StreamingSuiteBase import org.apache.spark.rdd.RDD import org.scalatest.{ BeforeAndAfter, FunSuite…
Tushar Sudake
  • 1,148
  • 1
  • 14
  • 25
11
votes
3 answers

learn Scala with TDD

I'm learning Scala now. I saw there are 2 test frameworks there, ScalaTest and Specs. My only problem is that I'm not still at ease with the language to decide which is better. Also I'm used to write tests before code, at the moment I have no clear…
Uberto
  • 2,712
  • 3
  • 25
  • 27
11
votes
2 answers

Exclude Specifically Tagged tests from SBT when using ScalaTest

I'm having a lot of frustration trying to run all my tests from sbt- while excluding a specific tag. Here is what I am trying to run: testOnly * -- -l "com.my.project.path.tags.ValidationTest" I've tried many variations of this command, including…
DanGordon
  • 671
  • 3
  • 8
  • 26
11
votes
4 answers

Scala testing with type enrichment

I've become attached to type enrichment, for example object MyImplicits{ implicit class RichInt(i: Int){ def complexCalculation: Int = i * 200 } } Which I use in code like this object Algorithm{ def apply(rand: Random) = { import…
Pengin
  • 4,692
  • 6
  • 36
  • 62
11
votes
6 answers

Scalatest Maven Plugin "no tests were executed"

I'm trying to use scalatest and spark-testing-base on Maven for integration testing Spark. The Spark job reads in a CSV file, validates the results, and inserts the data into a database. I'm trying to test the validation by putting in files of known…
Azuaron
  • 391
  • 3
  • 17
11
votes
2 answers

Mock a Spark RDD in the unit tests

Is it possible to mock a RDD without using sparkContext? I want to unit test the following utility function: def myUtilityFunction(data1: org.apache.spark.rdd.RDD[myClass1], data2: org.apache.spark.rdd.RDD[myClass2]):…
Edamame
  • 23,718
  • 73
  • 186
  • 320
11
votes
2 answers

ScalaTest - testing equality between two floating point arrays with error margin

Let's say I have a function that returns a array of doubles. I want to test this function and have calculated the correct value by hand. However since it's floating point numbers, I can't do direct comparisons so is there any sweet syntax by…
Johan S
  • 3,531
  • 6
  • 35
  • 63
11
votes
1 answer

How to run tests on every code change in IntelliJ IDEA from Scala sbt project?

I have a new Scala/sbt project set up in IntelliJ IDEA with ScalaTest and jUnit interface successfully installed as dependencies. I have one test that passes when I hit run or debug. My problem is that it doesn't rerun if I change something. I have…
Mark
  • 3,137
  • 4
  • 39
  • 76
11
votes
3 answers

how to make scalatest generate html report through sbt

The way to do this for specs2 based test in sbt is (testOptions in Test) += Tests.Argument(TestFrameworks.Specs2, "html") but how about scalatest? I've done lots of Google search, but cannot find a good explanation/solution.
Sheng
  • 1,697
  • 4
  • 19
  • 33
11
votes
2 answers

How to measure and display the running time of a single test?

I have a potentially long-running test written with scalatest: test("a long running test") { failAfter(Span(60, Seconds)) { // ... } } Even if the test finishes within the timeout limit, its running time can be valuable to the person who…
Petr
  • 62,528
  • 13
  • 153
  • 317