java - 在 Spock 中,如何测试从另一个静态方法调用的静态方法?
问题描述
这是我的课:
class Application {
public static void main(){
System.out.println("main called");
otherMethod();
}
public static void otherMethod(){
System.out.println("otherMethod called");
}
}
这是我的 spock 测试
def "Expect that Application.otherMethod() is called"(){
given:
def app = new Application()
when:
Application.main()
then:
1 * Application.otherMethod()
}
我怎样才能使这项工作?
解决方案
你没有。静态方法不应该有可见的副作用(理想情况下,它们应该是纯函数),并且对于客户端如何实现它们并不重要。
在您的简单情况下,您将调用移动otherMethod()
到构造函数中Application
并new Application()
从main
.
推荐阅读
- python-3.x - matplotlib 仅显示来自 stl 文件的部分网格
- java - 如何使用 Java Api 在 Bamboo 中获取当前分支名称
- javascript - 材料化进行电子邮件验证的 js 代码
- associations - CakePHP3 PUT 与关联实体
- javascript - 函数中的 JavaScript 函数 - TypeError:this.outputName 不是函数
- python - 从文件(文本)(如 python 等)执行 CURL 脚本(外部)
- java - 重启后广播接收器不工作
- javascript - 浏览器文本编辑器
- javascript - 在导航守卫中将 next() 放入 Promise 时发出警告
- ios - 在 UITableViewCell 中逐行显示字符串的动画