Springboot如何集成Junit4呢?
下文笔者讲述SpringBoot集成Junit4的方法分享,如下所示
Springboot集成Junit4的实现思路
1.引入相应的jar包
2.添加相应的注解
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = 启动类.class)
3.方法中即可使用相应的类进行测试
例:Springboot集成Junit4的示例
//一、引入依赖
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
//二、在test文件夹下编写测试类
package com.java265;
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;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = 启动类.class)
public class TestClassService {
@Autowired
TestService testService;
@Test
public void test(){
Boolean aBoolean = test.updateStatus(9L, "5");
System.out.println(aBoolean);
}
}
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


