spring添加junit测试

本文介绍如何使用JUnit 4.12与Spring Test 4.1.4进行集成测试,确保测试类正确加载Spring配置并调用业务逻辑。文章详细说明了所需依赖包及其版本一致性的重要性,并提供了一个具体的测试类示例。

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

junit-4.12.jar
spring-test-4.1.4.RELEASE.jar
hamcrest-core-1.4-atlassian-1.jar
需要这三个包
另外,spring-test包一定要和其他spring引用的jar包版本一致,否则,测试会报错

No tests found matching ...

@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration(locations={"classpath:spring.xml","classpath:spring-mybatis.xml"})

public class Test extends AbstractJUnit4SpringContextTests {

public static final Logger logger=Logger.getLogger(Test.class

@Resource

MusicService musicService;

@org.junit.Test

public void getU(){

List<Music> musiclist=musicService.SelectAllMusic();

System.out.println(musiclist);

}

}

切记,测试类名字不可取Test.java否则报错:
The import org.junit.Test conflicts with a type defined in the same file


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值