1、在【ruoyi-admin】的pom.xml下添加依赖
XML
<!-- 单元测试-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
2、update一下maven(确认单元测试已经添加进来)
3、添加在src下创建test模块(与main同级)
4.创建测试类
XML
import com.aide.CMSApplication;
import com.aide.mqtt.parse.domain.DataFile;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest(classes = CMSApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class UnitTest {
@Autowired
private DataFile dataFile;
@Test
public void test1() {
System.out.println(dataFile.toString());
}
}
5.测试结果