Spring整合Junit

Spring整合Junit,第1张

使用Spring整合Junit专用的类加载器

//设置类运行器
@RunWith(SpringJUnit4ClassRunner.class)
//设置Spring环境对应的配置类
@ContextConfiguration(classes = SpringConfig.class)
public class AccountServiceTest {
    //支持自动装配注入bean
    @Autowired
    private AccountService accountService;

    @Test
    public void testFindById(){
        System.out.println(accountService.findById(1));

    }

    @Test
    public void testFindAll(){
        System.out.println(accountService.findAll());
    }


}

在pom.xml文件导入相关依赖

    
      org.springframework
      spring-test
      5.2.10.RELEASE
    

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/905489.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-15
下一篇2022-05-15

发表评论

登录后才能评论

评论列表(0条)

    保存