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

Mockito's Answer in ScalaTest

Is there some alternative to Mockito's Answer in ScalaTest? I was going through its documentation, but didn't find anything. I would like to, for example, execute some logic on arguments of a stubbed method. In Mockito, I would do something like…
semberal
  • 2,204
  • 1
  • 21
  • 21
8
votes
1 answer

ScalaMock. Mock a class that takes arguments

Full disclosure: I'm very new to mocking and mocking frameworks. I'm trying to use ScalaMock because it seemed like the 'default' mocking framework to use with ScalaTest but I am happy to use any other framework which is compatible with…
jangoolie
  • 125
  • 1
  • 1
  • 4
7
votes
1 answer

Scala and Mockito with traits

I had a simple class that naturally divided into two parts, so I refactored as class Refactored extends PartOne with PartTwo Then the unit tests started failing. Below is an attempt to recreate the problem. The functionality of all three examples…
Pengin
  • 4,692
  • 6
  • 36
  • 62
7
votes
1 answer

Testing private methods that take generic type using PrivateMethodTester

How can I test a private method that takes a generic type using privateMethodTester in scala? Let's say I have the following method: private def parseValueForJsonKeyWithReturnType[A: TypeTag]( node: JsonNode, key: String, defaultValue:…
Nithin Chandy
  • 686
  • 1
  • 10
  • 28
7
votes
1 answer

unresolved dependency: com.artima.supersafe#supersafe_2.12.4;1.1.3: not found

I am trying to use scala test and write: resolvers += "Artima Maven Repository" at "http://repo.artima.com/releases" addSbtPlugin("com.artima.supersafe" % "sbtplugin" % "1.1.3") into plugins.sbt and build.sbt looks as…
softshipper
  • 32,463
  • 51
  • 192
  • 400
7
votes
3 answers

How to use fixture-context objects with async specs in ScalaTest?

I'm trying to use fixture-context objects with async testing in ScalaTest. The naive approach of simply combining the two doesn't compile. For example: import org.scalatest.AsyncWordSpec import scala.collection.GenTraversableOnce import…
steinybot
  • 5,491
  • 6
  • 37
  • 55
7
votes
0 answers

Executing PlaySpec tests with Scalatest from packaged binary

I have a Play project with functional tests. I am able to execute the tests with SBT. They are testing with a browser against a deployed application, i.e. with OneServerPerSuite with OneBrowserPerSuite ... Instead of executing the tests with SBT /…
Brett
  • 5,690
  • 6
  • 36
  • 63
7
votes
2 answers

How to implement a ScalaTest FunSuite to avoid boilerplate Spark code and import implicits

I try to refactor a ScalaTest FunSuite test to avoid boilerplate code to init and destroy Spark session. The problem is that I need import implicit functions but using before/after approach only variables (var fields) can be use, and to import it is…
angelcervera
  • 3,699
  • 1
  • 40
  • 68
7
votes
1 answer

ScalaTest assert and matchers

I used ScalaTest in my Scala Play project. But I have a question here, when to use normal assert(xxx === yyy) and when to use ScalaTest matchers like xxx should be yyy. Personally I prefer to use assert as it is simple and clean. Also can take…
ttt
  • 3,934
  • 8
  • 46
  • 85
7
votes
4 answers

How to set System property for a scalatest from sbt command line

A ScalaTest suite is using System.getProperty("my.command-line.property") What is the sbt command line to achieve this setting? I have tried SBT_OPTS="-Dmy.command-line.property=foo" sbt "test-only
WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560
7
votes
3 answers

Manually exclude some test classes in sbt

I usually do below command in my CI: clean update compile test publish However, I'd like to exclude 1 (or a few) test class from the sbt command line. How can I do this? (I don't want to change my code to use ignore, etc)
anuni
  • 889
  • 10
  • 26
7
votes
2 answers

Better way to compose test fixtures in ScalaTest

We have test fixtures using loan pattern. Leveraging this pattern to create "seed data" needed for a test to run. when test is dependent on data For e.g. following "save definition" should { "create a new record" in withSubject { implicit subject…
Vikas Pandya
  • 1,998
  • 1
  • 15
  • 32
7
votes
1 answer

Spying with mockito on Akka actor

I would like to spy on my actor instance, but it cannot be simply created with new keyword. I figured out following solution: val testActorSpy = spy(TestActorRef(new TestActor).underlyingActor) val testActorRef = TestActorRef(testActorSpy ) but…
Krever
  • 1,371
  • 1
  • 13
  • 32
7
votes
2 answers

Comparing Lists with scalatest

I am starting a new project using Scala and Akka and am having trouble writing tests. In my tests I am checking the equality of two List objects using should equal: actualBook should equal (expectedBook) Everything in my test suite compiles and…
davidrpugh
  • 4,363
  • 5
  • 32
  • 46
7
votes
1 answer

NoSuchMethodError while running Scalatest

I have created one small program and in order to test it I have write small Scala Test class. But when I tried to execute scala test I was getting below error, please advise, java.lang.NoSuchMethodError:…
Nishan
  • 375
  • 3
  • 16