springboot整合Junit 测试类

1、修改pom

<!-- 配置test启动器(自动整合spring-test、junit) -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>
2、编写测试类 (UserServiceTest)
import com.subject.DemoApplication;
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;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = DemoApplication.class)
public class DemocontrollerTest {

    @Autowired
    private Democontroller democontroller;

    @Test
    public void test01() {
        final String s = democontroller.test01();
        System.out.println("s = " + s);
    }
}
 
 
 

 

posted @ 2022-01-11 23:01  得好好活  阅读(145)  评论(0)    收藏  举报