• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple general getValue using some mocking library (Mockito?)

 
Oyvind Roth
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As part of generalizing getters and setters testing I am looking for a simple way of implementing the following method:



The signature would be like, I guess:



Relying on autoboxing for primitives would be quite OK.

I have been looking at PowerMockito and Mockito, but I have not figured out exactly how to put together the pieces. I could, of course, make a big if...else...else...else or switch of some kind, but my wish is something a bit more simple and elegant... :-)
 
Tomek Kaczanowski
author
Ranch Hand
Posts: 40
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hm, not sure if Mockito or PowerMock can help you here...

But what really attracted my attention is how you plan to use these random values generators in your tests? I ask, because I have seen a lot of tests which used random... and they are rarely better because of this.
 
Oyvind Roth
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tomek Kaczanowski wrote:Hm, not sure if Mockito or PowerMock can help you here...

But what really attracted my attention is how you plan to use these random values generators in your tests? I ask, because I have seen a lot of tests which used random... and they are rarely better because of this.


Of course, you're right. It's mostly to avoid the default values. Setting and then getting an int property valued 0 does not give me a safe feeling of having carried out a successful test :-) The same goes for an empty string.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic