gpt4 book ai didi

java - Pmd 规则 : Too many static imports may lead to messy code in unitTest is not violated

转载 作者:行者123 更新时间:2023-12-01 14:14:08 28 4
gpt4 key购买 nike

我有一个疑问,我有一个类,我在其中对导入常量使用不同的静态导入,我的问题是我收到错误消息:Too many static imports may lead to messy code .但是在单元测试中看起来这不是一个坏习惯。例如在单元测试类中,我使用这个导入有任何问题:

import static com.rccl.middleware.kidsclub.engine.web.controller.KidController.KID_FIND_PATH;
import static com.rccl.middleware.kidsclub.engine.web.controller.KidController.KID_LIST_PATH;
import static com.rccl.middleware.kidsclub.engine.web.controller.KidController.KID_PATH;
import static com.rccl.middleware.kidsclub.engine.web.controller.KidController.KID_REGISTER_ALL_PATH;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.times;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.request;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;```

相反在我的课上:
import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
import static org.springframework.http.HttpStatus.NOT_FOUND;
import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;

这些导入给我带来了问题,我收到了错误消息:过多的静态导入可能会导致代码困惑。我不太确定为什么。

我无法访问 pmd 文件来找出此问题的真正原因。有什么线索吗?

谢谢!

最佳答案

我已经使用 @SuppressWarnings("PMD.TooManyStaticImports") 来避免我类的这个问题。

关于java - Pmd 规则 : Too many static imports may lead to messy code in unitTest is not violated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58241730/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com