springboot项目 - 单元测试

选中要测试的类, 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);
    }
}

相关推荐