Maven无法成功运行我的JUnit测试,尽管它们在Eclipse上运行时没有任何问题。我无法从调试消息中解决它。
这可能与Spring配置有关,因为我的其他JUnit测试不依赖于Spring工作正常。
Adding surefire插件forkMode as Always也不起作用。
mvn install ... ... [INFO] --- maven-surefire-plugin:2.10:test(default-test)@AppServer --- [INFO] Surefire报告目录: C:.. \万无一失的报告
运行com.ws.impl.BrowserServiceImplTest测试运行:2,失败:2, 错误:0,跳过:0,经过的时间:0.016秒<<< FAILURE!
测试失败:com.ws.impl.BrowserServiceImplTest.testGetStatuses()
com.ws.impl.BrowserServiceImplTest.testGetSellers()
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:test-context.xml")
public class BrowserServiceImplTest {
@Autowired
private BrowserServiceImpl browserServiceImpl;
@Test
public void testGetStatuses() {
// test code
}
// more code
}
<failure type="java.lang.NullPointerException">java.lang.NullPointerException
at com.ws.impl.BrowserServiceImplTest.testGetStatuses(BrowserServiceImplTest.java:48)
</failure>
第48-49行
List<String> statuses = browserServiceImpl.getStatuses();
assertEquals(12, statuses.size());
测试context.xml中
<bean id="browserSvc" class="com.ws.impl.BrowserServiceImpl">
<property name="filterOptionsService" ref="filterOptionsService" />
</bean>
BrowserServiceImpl.java
@WebService(targetNamespace = "http://abc.def.com", portName = "BrowserPort", serviceName = "BrowserService")
public class BrowserServiceImpl implements BrowserService {
private FilterOptionsService filterOptionsService;
// more code
}