• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Mockito doubt

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I'm beginning to work with mockito, i took some course in pluralsight and now that i know how to use mockito and how it works, i don't know what to begin to apply unit testing, for example, i begin with one service, is a pretty short one, see it below:



And this is the test code i wrote:




So this test looks useless to me, if i mock the returning query, why then should i make a test for this service, i know tests must be independent from data, but in this case i don' t know if remove this test, or what exactly should i test from this service...
 
author & internet detective
Posts: 40747
827
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ricardo,
That's because you are mocking the wrong object. You don't want to mock the object under test. (As you noted, that's useless).

Instead, you want to mock the dependencies of the object under test. In this case, you want to mock JdbcTemplate. That lets you test the logic about the number of rows.
 
Ricardo Coto
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
mm nice Jeanne, that's a starting point to understand what to test... thanks.
 
I'm still in control here. LOOK at this tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic