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 15:35:39 浏览: 32
你可以尝试将测试方法名从`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的命名规范,更易读和维护。
相关推荐
![unitypackage](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)