如何用mockito模拟最后一堂课 [英] How to mock a final class with mockito
本文介绍了如何用mockito模拟最后一堂课的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个最终课程,如下所示:
I have a final class, something like this:
public final class RainOnTrees{
public void startRain(){
// some code here
}
}
我在其他类这样的课程中使用这个课程:
I am using this class in some other class like this:
public class Seasons{
RainOnTrees rain = new RainOnTrees();
public void findSeasonAndRain(){
rain.startRain();
}
}
和我的JUnit测试类 Seasons.java
我想模拟 RainOnTrees
类。我怎么能用Mockito做到这一点?
and in my JUnit test class for Seasons.java
I want to mock the RainOnTrees
class. How can I do this with Mockito?
推荐答案
这对于Mockito v1来说是不可能的,来自 Mockito常见问题解答:
This is not possible with Mockito v1, from the Mockito FAQ:
Mockito有什么限制
What are the limitations of Mockito
-
需要java 1.5+
Needs java 1.5+
无法模拟最终课程
.. 。
这篇关于如何用mockito模拟最后一堂课的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文