File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Testing and the fly likes Simple general getValue using some mocking library (Mockito?) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Simple general getValue using some mocking library (Mockito?)" Watch "Simple general getValue using some mocking library (Mockito?)" New topic
Author

Simple general getValue using some mocking library (Mockito?)

Oyvind Roth
Greenhorn

Joined: May 21, 2012
Posts: 2
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

Joined: Oct 26, 2005
Posts: 40

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.


Tomek Kaczanowski
Book author: Practical Unit Testing with TestNG and Mockito
http://practicalunittesting.com
Oyvind Roth
Greenhorn

Joined: May 21, 2012
Posts: 2
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simple general getValue using some mocking library (Mockito?)