I have an object that I mock JMockit NonStrictExcpection()in the @Before/ method of setUp()my test class so that it returns the value expected for the normal execution of my test class.
This is great for all of my test methods, with the exception of one test where I want to test the abnormal operation of this code.
I tried to create a new wait in the test method, which I thought would override the wait in the setUp method, but I found that the wait in the setUp method suppresses the new wait.
When I remove the wait for setUp, the test method behaves as expected (but all my other tests fail, naturally).
How can I encode my test class so that I can correctly determine the expectations for each test with a minimum amount of code? (I know that I could copy / paste the wait code into each test method, but I do not want to do this, if at all, can be avoided).
My test code looks something like this (note that this is sorta psuedocode and does not compile, but you get the idea):
public class TestClass{
@Before
public void setUp(){
new NonStrictExpectations() {{
mockObject.doSomething();
result = "Everyting is OK!";
}};
}
@Test(expected=Exception.class)
public void testMockObjectThrowsException(){
new NonStrictExpectations() {{
mockObject.doSomething();
result = "Something is wrong!";
}};
}
}
source
share