spring和junit整合测试
java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=testInjection],
{ExactMatcher:fDisplayName=testInjection(testJection.TestJection)],
{LeadingIdentifierMatcher:fClassName=testJection.TestJection,fLeadingIdentifier=testInjection]]
from org.junit.internal.requests.ClassRequest@51016012
请看测试代码:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:springmvc.xml")
public class TestJunit {
@Autowired
private User user;
@Test
public void test1(){
System.out.println(user);
}
}
执行以上代码时,出现错误!
最终确定错误原因:
是因为jar包版本冲突。spring-test的jar包版本和spring-context的jar包版本保持一致即可
此文希望可以帮助到大家。如有错误,请指教。
如果大家还有其他的情况或者好的解决方法,也望指教,感谢阅读。

本文介绍了一种Spring与JUnit整合进行单元测试的方法,并解决了因jar包版本冲突导致测试失败的问题。通过调整spring-test与spring-context的版本一致性,成功运行了测试。
753

被折叠的 条评论
为什么被折叠?



