SpringBoot-其他-测试

springboot 里要做单元测试,看下面
图片.png
0、在“SpringBoot-业-JPA”基础下进行
1、写测试类

package com.llhc.test;
import java.util.List;
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.SpringRunner;
import com.llhc.Application;
import com.llhc.dao.TestDao;
import com.llhc.model.TestJpa;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class TestJPA {
    @Autowired TestDao dao;
    @Test
    public void test() {
        List cs=  dao.findAll();
        for (TestJpa c : cs) {
            System.out.println("c.getName():"+ c.getName());
        }
         
    }
}

2、pom.xml加入:

 
      
            junit
            junit
            4.12
            test
        
         
        
            org.springframework.boot
            spring-boot-starter-test
            test
        

你可能感兴趣的:(SpringBoot-其他-测试)