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
21
votes
4 answers

How do I run both ScalaTest and JUnit tests with Gradle?

I've got a mixed Java / Scala project with both JUnit and ScalaTest tests. With the scalatest plugin, Gradle runs the ScalaTest tests in src/test/scala, but ignores the JUnit tests in src/test/java. Without the plugin, Gradle runs the JUnit tests…
David Moles
  • 48,006
  • 27
  • 136
  • 235
20
votes
4 answers

How to configure sbt test / ScalaTest to only show failures?

Is there a way to truncate the test results to only show result text for unit tests only when the unit test has failed? I'm working on a Scala project that has 850 unit tests, and the green text from the successful unit tests makes it difficult to…
nimda
  • 700
  • 7
  • 9
19
votes
1 answer

Not able to import Spark Implicits in ScalaTest

I am writing Test Cases for Spark using ScalaTest. import org.apache.spark.sql.SparkSession import org.scalatest.{BeforeAndAfterAll, FlatSpec} class ClassNameSpec extends FlatSpec with BeforeAndAfterAll { var spark: SparkSession = _ var…
himanshuIIITian
  • 5,985
  • 6
  • 50
  • 70
18
votes
1 answer

Why am I getting this error when running Scala 2.13 tests in IntelliJ, but not with Scala 2.12?

I am getting the following error when I try to run tests in IntelliJ (2019.1), Scala IntelliJ plugin v2019.1.8, with Scala 2.13: Exception in thread "ScalaTest-dispatcher" java.lang.NoSuchMethodError:…
GreenSaguaro
  • 2,968
  • 2
  • 22
  • 41
18
votes
1 answer

How to have SBT re-run only failed tests

Is there a way to have SBT re-run only the tests that have failed in the last run of the test suite? For example, if I run sbt test and 3 out of the 20 tests I run fail, is there any command I can run to have SBT just re-run those 3 tests that…
Christopher Wells
  • 1,918
  • 1
  • 15
  • 20
18
votes
5 answers

How to populate java.util.HashMap on the fly from Scala code?

I am unit testing java code from ScalaTest and would like to populate a java.util.HashMap within the same statement it gets declared. Is it possible to do this in Scala?
Nermin Serifovic
  • 1,327
  • 1
  • 8
  • 18
18
votes
2 answers

Handling Doubles in ScalaTest

I have just started using ScalaTest and I am using the following to compare two Doubles in my spec as follows: it should "calculate the price" in { val x = new X(10,10,12,1000) assert(x.price() === 185.92) } The spec is passing even…
user3248346
17
votes
2 answers

SBT Test Error: java.lang.NoSuchMethodError: net.jpountz.lz4.LZ4BlockInputStream

Getting Below exception , when i tried to perform unit tests for my spark streaming code on SBT windows using scalatest. sbt testOnly <> * * * * * * 2018-06-18 02:39:00 ERROR Executor:91 - Exception in task 1.0 in stage 3.0…
KK2486
  • 353
  • 2
  • 3
  • 13
17
votes
2 answers

How make tests always run in same order in Scalatest?

We use Spec trait for our tests in ScalaTest. when we run the entire suite, it does not always run in the same order. Most answers in google suggest defining a Suite and specifying all the test names. But this requires us to add the test name every…
Udayakumar Rayala
  • 2,264
  • 1
  • 20
  • 17
16
votes
7 answers

Why "could not find implicit" error in Scala + Intellij + ScalaTest + Scalactic but not from sbt

I have this code that is working 100% from sbt , executing sbt test but throw a compilation error in Intellij Idea. import org.scalatest.{BeforeAndAfter, FunSuite, GivenWhenThen} class SimpleTest extends FunSuite with GivenWhenThen with…
angelcervera
  • 3,699
  • 1
  • 40
  • 68
16
votes
3 answers

ScalaTest v3: why require to implement convertToLegacyEqualizer

Using ScalaTest 3.0.0 Environment: Scala 2.11.8, sbt 0.13.5, IntelliJ 14.1.4 build.sbt has only // NOTE: not using org.scalactic libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.0" % "test" The test below passed. However, IntelliJ marks…
Polymerase
  • 6,311
  • 11
  • 47
  • 65
16
votes
1 answer

ScalaTest: pass command line arguments to ScalaTest maven goal

How do I pass command line arguments to ScalaTest using its maven plugin? I was looking for something like TestNG's delegateCommandSystemProperties configuration, but the closest I could find in ScalaTest documentation were: argLine: Option to…
zihaoyu
  • 5,483
  • 11
  • 42
  • 46
15
votes
4 answers

How do I integrate ScalaTest with Spring

I need to populate my ScalaTest tests with @Autowired fields from a Spring context, but most Scalatest tests (eg FeatureSpecs can't be run by the SpringJUnit4ClassRunner.class -…
Duncan McGregor
  • 17,665
  • 12
  • 64
  • 118
15
votes
4 answers

How to test a Try[T] with ScalaTest correctly?

I have a method that returns a Try object: def doSomething(p: SomeParam): Try[Something] = { // code } I now want to test this with ScalaTest. Currently I am doing it like this: "My try method" should "succeed" in { val maybeRes =…
rabejens
  • 7,594
  • 11
  • 56
  • 104
15
votes
3 answers

Using JUnit @Rule with ScalaTest (e.g. TemporaryFolder)

I would like to be able to use JUnit rules such as TemporaryFolder or other TestRules we have already developed in-house. What is the best method to accomplish that? I'm aware of JUnitSuite but it doesn't seem to pick up the @Rule annotation. I…
Mifeet
  • 12,949
  • 5
  • 60
  • 108