springboot项目 - 单元测试

2021-05-02 10:30

阅读:389

标签:app   选中   stat   autowired   ext   org   ice   cto   项目   

选中要测试的类, Alt + Enter 出现 create Test, 选中junit4
要在有启动类的项目中创建
注意这两个注解:
@SpringBootTest(classes = WebApplication.class)
@RunWith(SpringRunner.class)


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 static org.junit.Assert.*;

@SpringBootTest(classes = WebApplication.class)
@RunWith(SpringRunner.class)
public class DocumentPoliciesReleaseControllerTest {

    @Autowired
    private DocumentPoliciesReleaseService service;

    @Test
    public void delete() {
        System.out.println("service = " + service);
    }
}

springboot项目 - 单元测试

标签:app   选中   stat   autowired   ext   org   ice   cto   项目   

原文地址:https://www.cnblogs.com/wqkeep/p/13202651.html


评论


亲,登录后才可以留言!