鉴于无法使用@Parameters 在 JUnit 类中创建对象,如何将对象传递给 JUnit 测试?
事实是该对象是由 Web 应用程序外部的服务动态创建的,我想在创建剩余进程(使用该对象)所需的大量资源之前测试它是否有效。
编辑:
public void doService(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
MyObject myObject = ... //Get Object from external service
JUnitCore runner = ... //Create runner
runner.run(MyTestCase.class); //throws exception when objet is not valid
...//Create the heavy resources and delegate to custom process
}
我的测试案例:
public class MyTestCase{
@Test
public void testValidObject(){
MyObject myObject = ...//How to retrieve MyObject here?
}
}