给若依添加单元测试
方案二(异常困难但企业开发一般用这个)
方案一(简单)
在 admin 模块中添加单元测试
S1.在 src 目录下创建 test.java.MapperTests 文件
S2.将以下内容复制进去
import com.ruoyi.RuoYiApplication;
import com.ruoyi.activity.domain.Activity;
import com.ruoyi.activity.mapper.ActivityMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = RuoYiApplication.class)
public class MapperTests {
@Autowired
private ActivityMapper activityMapper;
@Test
public void testSelectActivityById() {
Activity activity = activityMapper.selectActivityById(1);
System.out.println(activity);
}
@Test
public void testSelectActivityList() {
List<Activity> activityList = activityMapper.selectActivityList(new Activity());
System.out.println(activityList);
}
}
S3.将以下内容添加到 admin 的 pom.xml 中
<!-- 测试所需 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
S4.在 ActivityMapper 前添加 Mapper 注解
成功:
方案二(异常复杂但实用)
在 activity 子模块中添加单元测试