SpringBoot junit测试

来源:互联网 发布:淘宝下架时间规则 编辑:程序博客网 时间:2024/06/03 19:57
package com.example.demo.service;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 org.springframework.test.context.web.WebAppConfiguration;import com.example.demo.SpringBootTestApplication;@RunWith(SpringJUnit4ClassRunner.class)@SpringBootTest(classes=SpringBootTestApplication.class)//制定SpinrgBoot的启动类@WebAppConfiguration//由于是web项目,所以要模拟Servletontextpublic class TestHelloService {@Autowiredprivate HelloService service;@Testpublic void test() {service.speak();}}