Questions tagged [scalamock]

ScalaMock is a mocking framework for the Scala programming language.

ScalaMock provides fully type-safe mocking support for almost all Scala language features including:

  • mocking classes, traits and case classes
  • mocking functions and operators
  • mocking type parameterized and overloaded methods
  • support for type constraints
  • support for repeated parameters and named parameters
  • mocking Java classes and interfaces

The official Web site for the ScalaMock project is http://www.scalamock.org.

148 questions
1
vote
1 answer

ScalaMock - Mocking higher order functions

I need some help with how to mock higher order functions inside classes using ScalaMock import org.scalamock.scalatest.MockFactory import org.scalatest.{FlatSpec, Matchers} class TestSpec extends FlatSpec with MockFactory with Matchers { class…
1
vote
1 answer

How to mock a call by name function using ScalaMock?

I'd like to be able to mock my call-by-name function with ScalaMock, so it can run the passed function inside my mock. class MyTest extends Specification with MockFactory { trait myTrait { def myFunction[T](id: Int, name: String)(f: => T):…
earlymorningtea
  • 508
  • 1
  • 9
  • 20
1
vote
1 answer

ScalaMock: Mocking a Trait with initializations via lazy val

I've the following trait which I want to mock: trait TraitA extends TraitB { private lazy val internalObject = new ServiceA() internalObject.setSomeVal("someVal") internalObject.setSomeOtherval("someOtherVal") private lazy val…
Agraj
  • 466
  • 5
  • 19
1
vote
1 answer

Unable to stub a Class with overloaded constructors - Scalamock

I am trying to stub a class called 'Producer' with the following signature: class Producer[K, V](private val underlying : kafka.producer.Producer[K, V]) extends scala.AnyRef { def this(config : kafka.producer.ProducerConfig) = { /* compiled code…
Ankit Khettry
  • 997
  • 1
  • 13
  • 33
1
vote
2 answers

ScalaMock: Stub works only for first test

Recently I started usage of ScalaMock library in my unit tests and it works fine, until I want to use the same stab (declared globally in a test suite) in more than one test. Here is an example: import org.scalamock.scalatest.MockFactory import…
Alex Fruzenshtein
  • 2,846
  • 6
  • 32
  • 53
1
vote
1 answer

scalamock: how to mock curried method with repeated paramter

I am trying to mock the awscala.dynamodbv2.DynamoDB.putConditionalMethod How would one define an expects for a method which is curried and includes a repeated parameter: putConditional(tableName: String, attributes: (String, Any)*)(cond:…
Mark J Miller
  • 4,751
  • 5
  • 44
  • 74
1
vote
2 answers

Dependency Errors scalatest and scala mock

My build.sbt file looks as follows name := "cakepattern" version := "0.1" scalaVersion := "2.11.8" libraryDependencies ++= Seq( "org.scalatest" %% "scalatest" % "3.0.0" % "test", "org.scalamock" %% "scalamock-core" % "3.1.1" % "test", …
Abdul Rahman
  • 1,294
  • 22
  • 41
1
vote
2 answers

Stub a val of a trait with scalamock

In the following (simplified) example, how can I stub the value of a trait that inherits fields from a class with scalamock? trait MyTrait extends MyClass class MyClass(val location: Location) val expectedValue = ??? val dor: MyTrait =…
Make42
  • 12,236
  • 24
  • 79
  • 155
1
vote
0 answers

ScalaMock for datastax-spark cassandra connector method "joinWithCassandra"

I am trying to mock in Scala the joinWithCassandra method from datastax spark connector. I am getting error in compile. Please guide what am I doing wrong. Error:(59, 23) not enough arguments for constructor DStream: (ssc:…
1
vote
1 answer

Scalatest and scalamock, tests not passing when Futures are involved

I am new to scalatest and scalamock, but I've managed to write some tests. However, when a use Futures in my tests (mocking returning results and in classes themselves), tests don't seem to pass. I've written a minimal working example hosted on…
vicaba
  • 2,836
  • 1
  • 27
  • 45
1
vote
1 answer

Scala - Is there a way to mock trait, extended by companion object?

I'm using scalatest along with scalamock for my small project. I have created a trait and a class, along with its companion object. trait A{ def getSomething(arg1) } class B(field1).... object B extends A{ def apply(arg1) = new…
DorianOlympia
  • 841
  • 1
  • 10
  • 22
1
vote
2 answers

scalamock stubbing method with specific parameters fails on null

Hi I want to stub a method with specific parameters and to get the result with a helper method val myDAOMock = stub[MyDao] (myDAOMock.getFoos(_:String)).when("a").returns(resHelper("a")) //btw-is there a way to treat "a" as a parameter to the…
igx
  • 4,101
  • 11
  • 43
  • 88
1
vote
0 answers

Scala Unit Testing - Mocking an implicitly wrapped function

I have a question concerning unit tests that I'm trying to achieve using Mockito in Scala. I've also looked up ScalaMock but it sounds like the feature is not provided as well. I suppose that maybe I'm looking from a narrow way to the solution and…
1
vote
1 answer

How to write Expectations with ScalaMock?

This question seems pretty obvious I know, but i've tried everything that is written on the documentation and I cant't mock a single method on any classes. For this test, I am using scalaMock 3 for Scala 2.10 and ScalaTest…
Will
  • 2,057
  • 1
  • 22
  • 34
1
vote
0 answers

How to use scala mock to provide an alternative implementation of a class as stub for test?

I found in a project i'm about to contribute with some external lib, that for testing purpose they set up a mock database manager. However what this database manager does, is creating an in-memory database and working with it. This is for testing…
MaatDeamon
  • 9,532
  • 9
  • 60
  • 127