Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Testing
Search Coderanch
Advance search
Google search
Register / Login
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
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Testing
Junit - EasyMock - Mocking a method while testing another method in the same class
Tharpa Roberts
Greenhorn
Posts: 14
posted 8 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Let's say I have a class with two methods. One method calls the other method. I want to
test
the first method, but give a mock response for the second method. Is this possible in EasyMock?
Janeice DelVecchio
Bartender
Posts: 1849
15
I like...
posted 8 years ago
1
Number of slices to send:
Optional 'thank-you' note:
Send
I think you can do a partial mock. See notes here:
http://easymock.org/user-guide.html
You could do it without a mock too if the method is not private or static. Quick example:
public class Example{ public String methodA(){ String s = methodB() + "suffix"; return s; } String methodB(){ return "B"; } }
public class ExampleTest{ @Test public void methodA(){ Example e = new Example_Stub(); assertEquals("someOtherStringsuffix", e.methodA()); } } class Example_Stub extends Example{ String methodB(){ return "someOtherString"; } }
When you do things right, people won't be sure you've done anything at all.
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
[JUnit] Many cases for the same method
A few questions about Mock Objects and JDBC
tips for procedural cobol programmer to do java testing
EasyMock: mocking a call to the same object
Scope of JUnit testing
More...