GithubHelp home page GithubHelp logo

Comments (5)

olafurpg avatar olafurpg commented on September 28, 2024

Thank you for reporting! I don’t have any experience with mocking so I’m not familiar with what a library like mockito provides. My understanding is that mocking is helpful in certain kinds of codebases but mocking can often be avoided by using a different design (which might be more idiomatic Scala)

from munit.

MrPowers avatar MrPowers commented on September 28, 2024

@olafurpg - Here's a code snippet where mocking would be useful:

def sendMessageToSlack(text: String): Unit = {
  val slackApi = new SlackApi("someString")
  val slackMessage = new SlackMessage()
  slackMessage.setText(text)
  slackApi.call(slackMessage)
}

def mySillyFunction(): Int = {
  val res = 2 + 2
  sendMessageToSlack("We just computed 2 + 2!!!")
  res
}

Think you need mocking to be able to test sendMessageToSlack and mySillyFunction. In mySillyFunction, we don't actually want to run the sendMessageToSlack method. We just want to make sure that the method would be invoked with the argument "We just computed 2 + 2!!!".

I haven't used mockito-scala yet either. I will create a sample project and a blog post to discuss the key features. Will report back on this issue with my findings ;)

from munit.

olafurpg avatar olafurpg commented on September 28, 2024

After more consideration I believe mocking is outside the scope of this library. I'm open to add integration modules with existing mocking libraries if there's demonstrable value (like with munit-scalacheck). I think any remotely interesting mocking library will quickly outgrow MUnit in complexity to merit a separate repo.

from munit.

MrPowers avatar MrPowers commented on September 28, 2024

Sounds good, thanks for considering this.

from munit.

FloWi avatar FloWi commented on September 28, 2024

My understanding is that mocking is helpful in certain kinds of codebases but mocking can often be avoided by using a different design (which might be more idiomatic Scala)

Hi @olafurpg! Would you mind elaborating on that? In my scenario I have a complex trait generated by smithy4s and I would like to mock only a handful of functions for a certain test. I'd be interested in knowing how to do that the idiomatic scala way.

Edit: In case anyone else reads this who is using smithy4s - they thought about that already and you can use this feature. So my problem is solved already, but I'm still curious on how to tackle this the scala-way.

from munit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.