• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Mockito doubt

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • 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: 39339
755
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
mm nice Jeanne, that's a starting point to understand what to test... thanks.
 
I want my playground back. Here, I'll give you this tiny ad for it:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!