你需要服務器來運行的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)。 –