zoukankan      html  css  js  c++  java
  • SpringBoot集成Junit

    1.在pom.xml下添加Junit依赖:

    <!--添加junit环境的jar包-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
            </dependency>

    2.创建测试类:

    /**
     * Created by Administrator on 2019/2/14.
     */
    
    import com.zoctan.api.Application;
    import com.zoctan.api.dto.AccountWithRole;
    import com.zoctan.api.service.AccountService;
    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.test.context.SpringBootTest;
    import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    
    import java.util.List;
    
    /**
     * SpringBoot 测试类
     *
     * @RunWith:启动器 SpringJUnit4ClassRunner.class:让 junit 与 spring 环境进行整合
     * @SpringBootTest(classes={App.class}) 1, 当前类为 springBoot 的测试类
     * @SpringBootTest(classes={App.class}) 2, 加载 SpringBoot 启动类。启动springBoot
     * junit 与 spring 整合@Contextconfiguartion("classpath:applicationContext.xml")
     */
    @RunWith(SpringJUnit4ClassRunner.class)
    @SpringBootTest(classes = {Application.class})
    public class AccountTest {
    
        @Autowired
        private AccountService accountService; //要注入的bean
    
        @Test
        public void list(){
         //调用测试的方法
    final List<AccountWithRole> list = accountService.listAllWithRole(); System.out.println(list); for(AccountWithRole role : list){ System.out.println(role.getRoleName()); } } }
  • 相关阅读:
    Some notes in Stanford CS106A(4)
    Some notes in Stanford CS106A(3)
    Some notes in Stanford CS106A(2)
    Some notes in Stanford CS106A(1)
    将前台页面的数据传到后台的方法(不调用ajax,少量数据)
    12、(扩展)获取省份表,填充于下拉列表框的简易js
    iframe刷新问题
    MVC基础
    DataList
    序列化
  • 原文地址:https://www.cnblogs.com/cat520/p/12897114.html
Copyright © 2011-2022 走看看