清单 9. 修正场景 3 的 ServiceClassTest 类
... import com.agical.rmock.extension.junit.RMockTestCase; public class ServiceClassTest extends RMockTestCase { private ServiceClass serviceClass; private Collaborator collaborator; public void setUp(){ serviceClass = new ServiceClass(); Object[] objectArray = new Object[]{"exampleString", 5}; collaborator = (Collaborator)intercept(Collaborator.class, objectArray, "mockCollaborator"); } public void testRunServiceAndReturnFalse(){ collaborator.executeJob(); modify().returnValue("failure"); startVerification(); boolean result = serviceClass.runService(collaborator); assertFalse(result); } } |
RMockTestCase
类的导入预示着引入 RMock 框架功能。接下来,测试类现在将扩展 RMockTestCase
,而不是 MockObjectTestCase
。稍后,我将向您展示在 TestClass
对象仍为 RMockTestCase
类型的对象的测试用例中重新引入 MockObjectTestCase
。