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.
Printable View
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:Hope this helps...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...
}
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()?
Yeppers. You can easily check this yourself, you know... ;)Quote:
Thanks, I appreciate the help.. so for every test method that is called, the setup and tear down are executed?
Output: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...");
}
}
Setting up
test two...
Tearing down
Setting up
test one...
Tearing down
k, thanks for the quick reply too