Results 1 to 5 of 5
Thread: Mocking a class for Testing
- 09-20-2009, 07:02 PM #1
Member
- Join Date
- Sep 2009
- Posts
- 8
- Rep Power
- 0
Mocking a class for Testing
If I have a class called Library with a method as shown below
public String searchForBook(){
String bookNumberToBeSearched = new InputAndOutputHandling().obtainStringFromKeyboard( "Book Number");
.........
.........
}
where
class InputAndOutputHandling {
public String obtainStringFromKeyboard(String anotherString) {
.................
.................
}
}
If i am writing a test for Library class and the method shown above, how will i mock the IO handling class so that i can mock the keyboard entry.
I tried doing this with mockito
InputAndOutputHandling ioHandling = mock(InputAndOutputHandling.class);
when(ioHandling.obtainStringFromKeyboard("Book Number")).thenReturn("1");
But it isnt working.
Can anyone help?
- 09-20-2009, 08:05 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
What do you mean by "It isn't" working? What testing/mocking libraries are you using?
- 09-21-2009, 04:38 AM #3
Member
- Join Date
- Sep 2009
- Posts
- 8
- Rep Power
- 0
im using mockito..
by isnt working i mean, i dont think i am able to mock using the about piece of code.. when i am testing, its asking for the keyboard input.
- 09-21-2009, 09:04 AM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Then you need to read the manuals that came with your mocking libraries. I, for one, don't use that one but if I wanted to know how it works I would check the manuals for it.
- 09-22-2009, 10:23 AM #5
Member
- Join Date
- Sep 2009
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
XML to JSP Unit Testing
By Abder-Rahman in forum Advanced JavaReplies: 2Last Post: 02-15-2009, 12:35 AM -
testing program
By chrisbremen in forum New To JavaReplies: 6Last Post: 11-08-2008, 05:23 PM -
Testing JUnit PDE with Ant
By keynan in forum EclipseReplies: 0Last Post: 02-14-2008, 11:35 PM -
Mocking static methods of class
By Kat in forum New To JavaReplies: 3Last Post: 11-08-2007, 12:24 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks