• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mockito Made Clear - Mockito for reactive programming

 
Ranch Hand
Posts: 74
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ken,

Fellow jarhead here.

Thank you for bringing this book here and give us a chance to win it. I've been using Mockito for the past 2.5 years when I've joined my current company and I must say I am impressed with it's capabilities. Mockito is well established here as the standard testing framework for all projects, so we are already quite proficient in using it. Being a late joiner to the party I learn constantly about it, however most of it is from following existing examples and not based on an actual explanation. So it would be nice to find some answers in your book.

And now to here is a question. Recently we've started a project where we use reactive programming and we discovered that Mockito lacks certain capabilities out of the box and we have to rely on StepVerifier (from reactor.test) for example. So what is your experience in this area, especially regarding Mockito and it's capabilities, maybe future plans?

cheers.
 
Ranch Hand
Posts: 92
Mac Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've got a totally different profile when compared with Arzki, currently a mere student trying to learn and produce something useful, made contact with JUnit and Mockito more than 10 years ago while being an intership during 12 months in a company. I don't remember a thing about them, haven't made contact with them again ever since, though I'm getting closer to doing it again in my studies.

My question is: in comparision with JUnit, what would the the differences between them? Which would you recommend learning and why?

Thanks!
 
gunslinger & author
Posts: 169
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi R.J. --> Thanks for reading the newsletter. You're right, Mockito doesn't include anything specific for asynchronous coding, as you noted. I also use the StepVerifier when I'm using Project Reactor, almost always as part of a Spring app.

Still, Mockito can mock your dependencies, so if your reactive controller depends on a repository, for example, you can still mock that if you need to. For example, if you're testing a controller that returns a returned by a reactive repository, you can still ask Mockito to return one of those using the method to create one.

Hi Marco --> Mockito complements JUnit. Mockito tests are part of JUnit tests, though technically Mockito can work with other testing frameworks if you like. The vast majority are built on JUnit. The JUnit part sets up the class and methods you are testing and expresses the expected results as assertions. If the class you're testing has dependencies of its own, what Mockito can do is generate fake objects to represent those that return the desired values when called. You don't test the fakes. You test a class that depends on them.

If instead of using Mockito you use the real dependencies, that's fine. That's called an integration test (rather than a unit test), and it's a necessary part of making sure the system is working properly. I often think of it this way: if you drive a car to some destination, that's an integration test, or even a full end-to-end, or functional, test. If you get there and back, the test succeeded and you're good. But if something goes wrong, you take the car to a mechanic, and their job is to isolate the problem down to its source. Mockito helps you isolate one component from another, so you can diagnose where the real problems reside.

Hope that helps,

Ken
 
R.J. Arzki
Ranch Hand
Posts: 74
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ken,

Sure, we still use Mockito to mock our dependencies, we haven't ditched that. Just wanted to point out that we had to explore and learn new things along the way, because our "standard" framework wasn't assisting us as usual. But I feel that's part of the fun, to always learn and discover new approaches

best of luck,
 
Kenneth A. Kousen
gunslinger & author
Posts: 169
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it. Makes sense. A side benefit may be that an additional reply gives you another entry in the book raffle. If that's true, feel free to reply to this reply. :⁠-⁠)
 
R.J. Arzki
Ranch Hand
Posts: 74
1
IntelliJ IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am pretty sure the entries into the raffle are based on threads opened with questions, not with replies.

So, I guess, Marcos Silvestri will not be in the raffle if he only asked his question inside the topic I opened
reply
    Bookmark Topic Watch Topic
  • New Topic