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 / specs2: What if I don't have assertions? Expectations only in IsolatedMockFactory

If I don't actually have an explicit assertions like count must_== 1 a in Specs2 test, I'd get an error indicating no implicit could be found. // doesn't compile class Example extends Specification { "You need an assertion" >> { // hello! …
Toby
  • 9,523
  • 8
  • 36
  • 59
1
vote
0 answers

Can ScalaMock3 mock java.lang.Thread.sleep

Is there a way to mock sleep and set an expectation on it? class Foo { def func = { Thread.sleep(100) } } For example, in Ruby, I'd just add the stub to Thread. But with Scalamock, I'm not sure how to inject that mock into the class.
James
  • 1,841
  • 1
  • 18
  • 23
1
vote
1 answer

How to verify that a ScalaMocks stub of MailerAPI.send has been called?

How can I verify that the send(Email) method of a ScalaMock stub of play.api.libs.mailer.MailerAPI has been called? class SomeTests extends FunSuite with MockFactory { [...] val expEmail = play.api.libs.mailer.Email( "Test", …
aknuds1
  • 65,625
  • 67
  • 195
  • 317
1
vote
1 answer

Using a mocked object as an implicit in scala using scalamock

I am using a trait definition with various concrete derivatives and implicit to inject dependancies into objects and also to mock out parts of the system when unit testing. The problem is that when a mocked version of a type is used as an implicit…
IUnknown
  • 2,596
  • 4
  • 35
  • 52
1
vote
1 answer

Is it possible to mock a function that is defined within another function?

I have some functions that access a database, which I need to mock for testing purposes. For ease of use, I would like to define these functions within another function, where I can leverage scope to reduce the number of arguments I have to pass. I…
David
  • 13,133
  • 1
  • 30
  • 39
1
vote
0 answers

Cannot use Matchers when mocking with Scalamock

We are trying to run a test with ScalaMock and ScalaTest using the matcher should be. The code is the following: import org.junit.runner.RunWith import org.scalamock.scalatest.MockFactory import org.scalatest._ import…
dierre
  • 7,140
  • 12
  • 75
  • 120
0
votes
1 answer

Unit test for a method, which calls other methods

I have the class A with private methods a and b and public method c. Methods a and b are covered by tests. The public method c is used with a parameter, so it can call a or b with if stmt I want test method c with behavior-based test (test a called…
andrey.ladniy
  • 1,664
  • 1
  • 11
  • 27
0
votes
0 answers

Mocking scala object gives Cannot mock/spy class PQR

I have a scala class where i am accessing a method of an object from third party library. While unit testing the scala class, I want to mock this third party method call. But I am getting below error Cannot mock/spy class PQR Mockito cannot mock/spy…
BigDataLearner
  • 1,388
  • 4
  • 19
  • 40
0
votes
0 answers

Need help testing a RestartFlow using Akka Stream Testkit

I have a following flow using Akka Stream scaladsl: @testOnly def restartableFlow: Flow[MyEvent, AmqpSendResult, NotUsed] = RestartFlow .withBackoff(restartSettings) { () => Flow[MyEvent] .mapAsyncUnordered(3)(acceptMessages)…
vasigorc
  • 882
  • 11
  • 22
0
votes
0 answers

Mocking case classes as properties of an object

Consider a case class: case class configuredThing[A, B](param: string) { val ... def ... } Test code was able to be partially written for configuredThing which has some methods on it that make some external calls to other services. This case…
Jeremie
  • 290
  • 3
  • 10
0
votes
1 answer

How to use scalamock for the awssdk

I have a function that has the following type signature: def post(target: String, partition: String, payload: String): IO[Boolean] In this function, a call is placed to a third party to post this data to a service through the awssdk. For testing, I…
Jeremie
  • 290
  • 3
  • 10
0
votes
2 answers

ScalaMock : expect a Double within some tolerance

I am using a MockFunction1, expecting an argument and expecting it to be called once. mockFunction.expects(result).once() The type of result object contains several values of type Double. I want the expected result object to match the actual within…
ksceriath
  • 184
  • 1
  • 12
0
votes
1 answer

Is it possible to mock / stub methods of the same test class with ScalaMock?

With Mockito and other testing frameworks there are usually ways to mock functionality of a method within the test class. I couldn't seem to get ScalaMock to accept the same way. class A { def methodUnderTest() def…
gigapogg
  • 51
  • 6
0
votes
1 answer

Mock class with Configuration as arguments

How do I mock the class which has Configuration(play.api) injected as arguments to its constructor? class SomeScalaClass @Inject(config: Configuration){ val someValue = config.get[String]("someValueInConfig") def abc:Int = { .. .. …
Siddharth Shankar
  • 489
  • 1
  • 10
  • 21
0
votes
1 answer

scalatest - test a method of Future[S] with fallbackTo

Premise: When my API responds to a request for the User object, I want to try enriching it with the properties of case class PartnerView(id: String, vipStatus: Option[Boolean], latestSession: Option[Timestamp]. Since the database can be unreliable…