架构性调整【懒得区分了,哈哈哈哈】,主要是跑通了第一个功能测试
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
package com.guo.learningprogresstracker.controller;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.guo.learningprogresstracker.dto.request.TaskRequest;
|
||||
import com.guo.learningprogresstracker.dto.response.TaskInfoResponse;
|
||||
import com.guo.learningprogresstracker.entity.CommonResult;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@SpringBootTest
|
||||
class TaskControllerTest {
|
||||
|
||||
@Autowired
|
||||
private TaskController taskController;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
StpUtil.login("测试用户", "test_driver");
|
||||
}
|
||||
@Test
|
||||
void addTask() {
|
||||
TaskRequest taskRequest = mock(TaskRequest.class);
|
||||
// 设置学习任务的名称
|
||||
when(taskRequest.getTaskName()).thenReturn("测试任务名称");
|
||||
|
||||
// 设置学习材料的存储URL
|
||||
when(taskRequest.getMaterialUrl()).thenReturn("http://example.com/material");
|
||||
|
||||
// 设置用户设置的任务紧急性
|
||||
when(taskRequest.getUrgency()).thenReturn(5);
|
||||
|
||||
// 设置用户设置的任务重要性
|
||||
when(taskRequest.getImportance()).thenReturn(3);
|
||||
|
||||
// 设置任务的内容难度
|
||||
when(taskRequest.getContentDifficulty()).thenReturn(4);
|
||||
|
||||
// 设置任务的未来价值
|
||||
when(taskRequest.getFutureValue()).thenReturn(5);
|
||||
|
||||
// 设置用户对任务的主观优先级
|
||||
when(taskRequest.getSubjectivePriority()).thenReturn(2);
|
||||
CommonResult commonResult = taskController.addTask(taskRequest);
|
||||
|
||||
// 验证 addTask 是否被调用一次
|
||||
assertEquals(commonResult.getCode(), 200,"测试数据插入失败");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void showTask() {
|
||||
String taskId = mock(String.class);
|
||||
TaskInfoResponse mockData = mock(TaskInfoResponse.class);
|
||||
|
||||
CommonResult commonResult = taskController.showTask(taskId);
|
||||
assertEquals(commonResult.getCode(),200,"获取数据失败");
|
||||
assertNotNull(commonResult.getData(),"返回值中不存在数据");
|
||||
assertEquals(commonResult.getData(),mockData,"返回值携带数据不正确");
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateTask() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteTask() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void listTasks() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user