package com.songhaozhi.mayday; import com.songhaozhi.mayday.model.domain.Category; import com.songhaozhi.mayday.service.CategoryService; import org.junit.Test; import org.junit.jupiter.api.Assertions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import java.util.List; @SpringBootTest public class TestCategoryService { @Autowired CategoryService Categoryservice; @Test public void testFindCategory() { List<Category> Category = CategoryService.findCategory(); Assertions.assertEquals(5,Category.size()); } } 怎么改
时间: 2024-04-08 19:35:39 浏览: 220
你可以尝试将测试方法名从`testFindCategory()`改为更具描述性的名称,例如`testFindAllCategories()`。此外,还可以将`CategoryService`的变量名改为小驼峰命名法,即`categoryService`。修改后的代码如下所示:
```java
package com.songhaozhi.mayday;
import com.songhaozhi.mayday.model.domain.Category;
import com.songhaozhi.mayday.service.CategoryService;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
@SpringBootTest
public class TestCategoryService {
@Autowired
CategoryService categoryService;
@Test
public void testFindAllCategories() {
List<Category> categories = categoryService.findCategory();
Assertions.assertEquals(5, categories.size());
}
}
```
这样修改后的代码更符合Java的命名规范,更易读和维护。
阅读全文