• 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 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: 41860
908
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic