It is not possible to mock static methods of java.lang.System to avoid interfering with class loading what leads to infinite loop
时间: 2024-05-25 20:13:45 浏览: 12
That is correct. Java's class loading mechanism relies on the static methods of `java.lang.System`, such as `System.out` and `System.err`, which cannot be mocked using traditional mocking frameworks. As a result, attempting to mock these static methods can cause interference with the class loading process and may result in an infinite loop or other unexpected behavior. To avoid this, it's best to avoid mocking these static methods altogether.
相关问题
org.mockito.exceptions.base.MockitoException: Cannot mock/spy class java.lang.Integer Mockito cannot mock/spy because : - final class
这个错误通常是因为您正在尝试使用Mockito来模拟或监视一个final类(如java.lang.Integer)。Mockito无法模拟或监视final类,因为它们不能被子类化。解决这个问题的方法是使用一个真实的实例代替模拟或监视。如果您需要对final类进行模拟或监视,您可以使用PowerMock等其他库,但是这不是推荐的做法,因为它可能会导致代码变得更加脆弱。
Caused by: java.lang.RuntimeException: MockitoUtil: Misusing of MockitoUtil, Please tell MockitoUtil which container you want to mock frist, example : MockitoUtil.in(container).mock(....)
根据您提供的信息,看起来是您使用了一个叫做MockitoUtil的工具类,并且在使用它时出现了一个异常。根据异常信息,您需要在使用MockitoUtil时先指定要mock的容器,然后再进行mock操作。例如:
```
MockitoUtil.in(container).mock(...);
```
其中,container是指您要mock的容器,例如Mockito.mock()方法返回的对象。请确保在使用MockitoUtil时按照这种方式进行操作,以避免出现此异常。
相关推荐
![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)