SpringBoot整合Junit

5.2 SpringBoot整合Junit

5.2.1 添加Junit的起步依赖



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

5.2.2 编写测试类

@RunWith(SpringRunner.class)
@SpringBootTest
public class SpringbootJunitApplicationTests {

    @Test
    public void contextLoads() {
        System.out.println("这是一个测试类");
    }

}

其中,SpringRunner继承自SpringJUnit4ClassRunner,使用哪一个Spring提供的测试测试引擎都可以

public final class SpringRunner extends SpringJUnit4ClassRunner

@SpringBootTest的属性指定的是引导类的字节码对象
5.2.3 控制台打印信息


2019-05-24 21:27:00.918  INFO 7888 --- [           main] c.i.s.SpringbootJunitApplicationTests    : Starting SpringbootJunitApplicationTests on MicroWin10-1923 with PID 7888 (started by Administrator in F:\win10\SpringBoot\springboot_junit)
2019-05-24 21:27:00.918  INFO 7888 --- [           main] c.i.s.SpringbootJunitApplicationTests    : No active profile set, falling back to default profiles: default
2019-05-24 21:27:04.377  INFO 7888 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-05-24 21:27:05.215  INFO 7888 --- [           main] c.i.s.SpringbootJunitApplicationTests    : Started SpringbootJunitApplicationTests in 4.831 seconds (JVM running for 6.413)
这是一个测试类
2019-05-24 21:27:05.532  INFO 7888 --- [       Thread-2] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'

Process finished with exit code 0

你可能感兴趣的:(SpringBoot)