• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

TestCase Fail : Actual Result Null

 
Ranch Hand
Posts: 157
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am creating the test case for the method as in attached file. I am using mockito here as my method have external dependencies. I have issue at in my method that i am testing, but not actually find out.

Thanks
test.png
[Thumbnail for test.png]
Open with Notepad
 
Marshal
Posts: 5114
319
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please include the code you're talking about in the post itself. Screen shots of code are no good.

Also be sure to tell us the exact problem you're having. Your question as it is now doesn't make much sense to me.
 
vivek dhiman
Ranch Hand
Posts: 157
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the code.


 
Tim Cooke
Marshal
Posts: 5114
319
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... and the exact problem you are having with that code is?
 
vivek dhiman
Ranch Hand
Posts: 157
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
returns null.
 
Marshal
Posts: 16631
278
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Test code like this is why people rail against Mocks and proclaim that mocks are evil.

This is very smelly test code. What your test code is telling you is: "This design is hard to test!"

Listen to your test code and go back and rethink your design. Why does your design require so much test setup? Are your objects leaking too much implementation detail? Are there way too many collaborations? Do some collaborations need to be pushed down further away, so higher-level test code doesn't have to care about them?

Solving your problem with the null return value is just delaying the inevitable pain you will suffer later on if you continue with your current design. And I can most certainly assure you that the pain you will feel later will be much greater than the pain you feel now. Much, much greater.
 
Junilu Lacar
Marshal
Posts: 16631
278
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vivek dhiman wrote:


And if you still are lost after the questions I suggested before, look at the code above and ask yourself "Why should anybody doing a search care or have to know about config and resourceResolver?"

Your test should drive to think that this should be sufficient for a client to perform a search:

I'll leave it up to you to read about Java 8 lambda expressions and method references if you're so inclined to do something like the latter.

But think how this can influence your testing strategy and if it can help make your test code better.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic