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

How to use ScalaMock to evaluate that function was called with certain Spark Dataframe parameter and have useful output

i've been looking at: http://scalamock.org/user-guide/advanced_topics/ https://scalamock.org/user-guide/matching/ https://scalamock.org/quick-start/ but not quite got the result I want yet essentially I had this test scenario("myFunction reads…
chrispepper1989
  • 2,100
  • 2
  • 23
  • 48
0
votes
1 answer

What is the better approach on functional testing playframework with scala with Injection

I am using scala 2.8 and I am a newbie in scala. I have a challenge testing this endpoint due to injection. Below is my endpoint @Singleton class AuthController @Inject()( cc:ControllerComponents …
Muyinda Rogers
  • 147
  • 3
  • 13
0
votes
1 answer

Should I Mock the Trait or Mock the Class Using Scala Mock

Say I have the following: @ImplementedBy(classOf[DefaultFoo]) trait Foo { def a (s : String) : Int } class DefaultFoo @Inject()() extends Foo{ override def a (s : String) = 1 } @ImplementedBy(classOf[DefaultBaz]) trait Baz { def b (s :…
Mojo
  • 1,152
  • 1
  • 8
  • 16
0
votes
1 answer

How to mock a method whose parameter is a new instance in scala

I have a method in a class: def delete(Token, Client, Scope): Future[Int] and this method is called elsewhere in another class inside another method as: acr.delete(Token(token), client, scope) where token is a String and client and scope are types…
Saturnian
  • 1,686
  • 6
  • 39
  • 65
0
votes
1 answer

ScalaTest with mocked object

I found some simple examples, but nothing works. a model: class Product() { var price: Int = 0 var stock: Int = 0 def addPrice(price: Int): Int = { this.price = price this.price } def addStock(qty: Int): Int = { this.stock +=…
AlleXyS
  • 2,476
  • 2
  • 17
  • 37
0
votes
1 answer

Discard Non Unit Value Compiler Error For Assertion

I am getting the following compiler error as I switched on the compiler flags as per sbt-toplecat. await(myService(request).value).isLeft shouldBe true Now compiler complains: discarded non-Unit value await(myService(request).value).isLeft shouldBe…
Mojo
  • 1,152
  • 1
  • 8
  • 16
0
votes
1 answer

Scala mock : call Instance of spy mock when other class Instance is initiated inside the object

I Have a class called SomeClass in scala & SomeClass object. now I need to Mock the OtherClass which is instantiated in SomeClass object class SomeClass { import SomeClass._ def…
Kalpish Singhal
  • 382
  • 1
  • 3
  • 20
0
votes
1 answer

Remocking a mock function

Say I have trait: trait A { def a(): Boolean } And mock + testcase: trait Fixture { val mockA = mock[A] (mockA _).returns(true) } "mock must return true" in new Fixture { mockA() must equal(true) } Now, I want to re-mock the value…
TTT
  • 1,952
  • 18
  • 33
0
votes
1 answer

ScalaMock diffculty mocking HttpResponse

I am trying to run the following test: import AV_Enums.TimeSeriesFunctions import org.scalamock.scalatest.MockFactory import org.scalatest.funsuite.AnyFunSuite import org.scalatest.matchers.must.Matchers.{be, _} import…
LeYAUable
  • 1,613
  • 2
  • 15
  • 30
0
votes
1 answer

Error when trying to mock a DataFrameReader object when using ScalaMock

I want to test a method we have that is formatted something like this: def extractTable( spark: SparkSession, /* unrelated other parameters */ ): DataFrame = { // Code before that I want to test val df = spark.read .format("jdbc") …
Jared DuPont
  • 165
  • 2
  • 14
0
votes
1 answer

Test class with implicit class using ScalaMock

Suppose I have a trait with read operations wrapped inside a Try block: import scala.util.Try trait ReadingProvider[T] { def readTable(tableName: String):Try[T] } Also a class which provides methods for reading with spark and an implicit class…
sanyi14ka
  • 809
  • 9
  • 14
0
votes
2 answers

Scala test dependent methods used to calculate vals are executed only once

I am new to scala, and I'm trying figure out the best way to test the following process. I have a class that gets a list of numbers from constructor parameter. The class supports various operations on the list, some operations may depend on the…
ssj_100
  • 149
  • 1
  • 11
0
votes
2 answers

How to pass a scala class in a mock

I have a scala class A and there is a method doSomething in it. There is another class B class B(name: String) there is another class C class C { def doSomethingElse(b: B): String { /// some logic //// } } class A(c: C) { def…
user9920500
  • 606
  • 7
  • 21
0
votes
1 answer

How to mock a polymorphic function with manifest in Scalamock?

I am trying to mock a polymorphic function belonging to a trait in scala. The method is parameterized with [T: Manifest] An minimum working (or failing, should I say) example is the following: class ScalaMockTest extends FlatSpec with MockFactory…
RvdV
  • 406
  • 3
  • 10
0
votes
1 answer

How to mock tail recursive functions?

I want to test my code which has a few tail recursive functions. I couldn't mock the tail recursive functions because they need to declared either Final or Private. Most mocking frameworks don't support mocking such methods, the ones that support…
H Sridhar
  • 71
  • 7