在单元测试中验证私有方法调用的顺序 [英] Verifying sequence of private method calls in unit testing

查看:115
本文介绍了在单元测试中验证私有方法调用的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下课程:

class MyClass {

  public void doIt() {
     methodOne();
     methodTwo();
     methodThree();
  }

  private void methodOne() {
     // ...
  }

  // rest of methods similar...

}

我的目的是验证当我调用doIt()时,将按该顺序调用metodOne(),methodTwo()和methodThree()方法.

My intention is to verify that when i invoke doIt(), methods metodOne(), methodTwo() and methodThree() will be invoked, in that order.

我正在使用 mockito 进行模拟.有谁知道我该如何测试这种情况?

I'm using mockito for mocking. Does anyone knows how i can test this scenario?

推荐答案

讨厌成为这个人,但是:根本不要测试这个.测试输出,副作用,结果-而不是实现.

Hate to be the person but: simply don't test this. Test the output, side effects, results - not the implementation.

如果您真的想确保顺序正确,请将这些方法提取到单独的类中并进行模拟.

If you really want to ensure the correct order, extract these methods into separate class(es) and mock them.

这篇关于在单元测试中验证私有方法调用的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆