你需要服务器来运行的java.class,答案是否定的,除非直到如果您有任何EJB组件从您的服务调用,或者你的服务需要一些外部web服务来响应(这里你可能需要模拟这个服务来提供模拟数据或者在服务器上运行服务) 我有服务调用数据访问层,有时服务调用另一个服务。
所有你需要在你的测试类
@ContextConfiguration({ "classpath:spring-context.xml", "classpath:otherservice-context.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
@Component
public class TestJuint{
@Autowire
private otherService otherServiceImpl;
@Autowire
private service serviceImpl;
@Test
public void testDummy{
serviceImpl.addDummy(dummyObj);
}
}
想,如果你需要有一些其他包装的另一个服务,那么你可能想在上下文配置其上下文文件,使Spring上下文配置它的bean参考将在春季环境中自动装配
请看'@ ContextConfiguration'注释及其用法。你可以指定你的XML配置'applicationContext'被加载到内存中。 – Hrishikesh
请阅读[10。测试(http://docs.spring.io/spring/docs/4.0.x/spring-framework-reference/html/testing.html)。 –