Comments (5)
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.
@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.
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.
Sounds good, thanks for considering this.
from munit.
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)
- Async tests failing on Scala Native
- Broken Scala Native tests on v1.0.0-M9 HOT 3
- How do I use munit snapshots?
- Drop Support for Scala 2.11 HOT 2
- Broken compileErrors behavior on Scala 3 HOT 1
- `assertNotEquals` produces unhelpful message on assertion fail. HOT 1
- Document timeout behavior HOT 11
- Unhandled errors in tests reported incorrectly in XML reports
- Failed test case details are not printed
- Document how to change fixture ordering
- Feature Request: full support for generic classes/types in custom value printing
- Request: Publish internal difflib as a micro-library HOT 3
- compileErrors doesn't return all errors HOT 8
- Error when run `+publishLocal` HOT 10
- Extract munit-scalacheck to a different repo/sbt project HOT 1
- Publish for Scala Native 0.5, please HOT 6
- When using singleton types `assertEquals` does not work but `==` does
- `ExceptionInInitializerError` causes test to hang for entire timeout HOT 2
- Full stack trace for assertEquals HOT 5
- `munit` has gotten perceivably slower when bumping `v0.7.29` => `v1.0.0`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from munit.