Spring自带测试模块,是基于Junit基础上的。
添加junit和spring-test依赖,POM.xml。
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>5.2.0.RELEASE</version> </dependency> </dependencies>
纯注解方式整合junit单元测试框架测试类
//加载spring自有测试类 @RunWith(SpringJUnit4ClassRunner.class) //加载Spring配置类或Spring配置文件 //@ContextConfiguration(classes={SpringConfig.class}) @ContextConfiguration(locations = {"classpath:applicationContext.xml"}) public class AnnotationTest { //依赖注入 @Autowired @Qualifier("accountService") private AccountService accountService; @Test pulbic void test(){ List<Account> accountList = accountService.queryAccountList(); accountList.forEach(System.out::println); } }
posted on
浙公网安备 33010602011771号