-
Easy mock : Reseting mock objects state
if I have multiple test cases such as :
public void testA () {
...
}
public void testA () {
...
}
From test case to test case, when are the mock objects reset()? or are they ever reset()? or must I manaully reset them at the end of each test case.
-
This doesn't seem to be a java programming question.
Are you working in a special environment?
What's a mock object?
What does "reset an object" mean?
-
I apologize, most of the terminology I was using is pretty standard with the concept of mock objects, but then you would need to know what a mock object is wouldn't you? 
Easymock is a package that I am using to "mock up" objects. If you google "mock objects" you could found oodles of resources. I guess I was hoping for some help from someone that has used "easymock" before...
thanks
-
What testing framework are you using? If you're using JUnit, just override the protected setUp() method in TestCase and initialize your mocks there. You may also put logic in the tearDown() method to clean up anything that needs it. These methods get called by the framework for *each* test method.
Example:
Code:
public class ExampleTest extends TestCase {
public ExampleTest(String s) {
super(s);
}
protected void setUp() throws Exception {
// test init goes here...
}
protected void tearDown() throws Exception {
// cleanup goes here...
}
// test methods follow...
}
Hope this helps...
Last edited by yawmark; 09-15-2005 at 08:34 AM.
-
Thanks, I appreciate the help.. so for every test method that is called, the setup and tear down are executed?
sorry, I just wanted to reiterate over that concept one more time. So if I have 5 test cases, both methods are executed 5 times in the order of:
setup(), myTestCase(), tearDown()?
-
Thanks, I appreciate the help.. so for every test method that is called, the setup and tear down are executed?
Yeppers. You can easily check this yourself, you know... 
Code:
import junit.framework.TestCase;
public class DemoTest extends TestCase {
public DemoTest(String s) {
super(s);
}
protected void setUp() throws Exception {
System.out.println("Setting up");
}
protected void tearDown() throws Exception {
System.out.println("Tearing down");
}
public void testOne() throws Exception {
System.out.println("test one...");
}
public void testTwo() throws Exception {
System.out.println("test two...");
}
}
Output:
Setting up
test two...
Tearing down
Setting up
test one...
Tearing down
-
k, thanks for the quick reply too
Similar Threads
-
Replies: 0
Last Post: 02-11-2003, 01:10 AM
-
By Stephen in forum VB Classic
Replies: 3
Last Post: 08-15-2002, 04:34 PM
-
By Lars Netzel in forum .NET
Replies: 5
Last Post: 05-08-2002, 09:23 AM
-
Replies: 13
Last Post: 03-22-2002, 06:10 AM
-
By Richard Dalton . in forum Architecture and Design
Replies: 33
Last Post: 07-30-2001, 02:11 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks