Spring单元测试ExceptionInInitializerError问题解决

该博客讨论了在进行Spring框架的单元测试时,JUnit版本的重要性。作者指出,使用了JUnit 4.9,但实际需要的是4.12或更高版本以确保测试的顺利运行。示例代码展示了如何配置`@RunWith(SpringJUnit4ClassRunner.class)`和`@ContextConfiguration`注解进行Spring的上下文加载,并执行了一个简单的`@Test`方法来查询所有客户。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class CustomerDaoTest {
    @Autowired
    CustomerDao customerDao;

    @Test
    public void findAll(){
        List<Customer> customerList = customerDao.findAll();
        System.out.println(customerList);
    }
}

在这里插入图片描述
原因:junit我版本是4.9,起码得4.12或以上!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值