<small id='k2NCt'></small><noframes id='k2NCt'>

      <i id='k2NCt'><tr id='k2NCt'><dt id='k2NCt'><q id='k2NCt'><span id='k2NCt'><b id='k2NCt'><form id='k2NCt'><ins id='k2NCt'></ins><ul id='k2NCt'></ul><sub id='k2NCt'></sub></form><legend id='k2NCt'></legend><bdo id='k2NCt'><pre id='k2NCt'><center id='k2NCt'></center></pre></bdo></b><th id='k2NCt'></th></span></q></dt></tr></i><div id='k2NCt'><tfoot id='k2NCt'></tfoot><dl id='k2NCt'><fieldset id='k2NCt'></fieldset></dl></div>

        <bdo id='k2NCt'></bdo><ul id='k2NCt'></ul>

        <legend id='k2NCt'><style id='k2NCt'><dir id='k2NCt'><q id='k2NCt'></q></dir></style></legend>
      1. <tfoot id='k2NCt'></tfoot>
      2. 如何验证没有使用 Mockito 调用特定方法?

        时间:2023-09-26
      3. <small id='cLR8O'></small><noframes id='cLR8O'>

          <bdo id='cLR8O'></bdo><ul id='cLR8O'></ul>
            <tbody id='cLR8O'></tbody>
          <i id='cLR8O'><tr id='cLR8O'><dt id='cLR8O'><q id='cLR8O'><span id='cLR8O'><b id='cLR8O'><form id='cLR8O'><ins id='cLR8O'></ins><ul id='cLR8O'></ul><sub id='cLR8O'></sub></form><legend id='cLR8O'></legend><bdo id='cLR8O'><pre id='cLR8O'><center id='cLR8O'></center></pre></bdo></b><th id='cLR8O'></th></span></q></dt></tr></i><div id='cLR8O'><tfoot id='cLR8O'></tfoot><dl id='cLR8O'><fieldset id='cLR8O'></fieldset></dl></div>

            <tfoot id='cLR8O'></tfoot>

                  <legend id='cLR8O'><style id='cLR8O'><dir id='cLR8O'><q id='cLR8O'></q></dir></style></legend>
                  本文介绍了如何验证没有使用 Mockito 调用特定方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  如何验证方法是否没有在对象的依赖项上调用?

                  How to verify that a method is not called on an object's dependency?

                  例如:

                  public interface Dependency {
                      void someMethod();
                  }
                  
                  public class Foo {
                      public bar(final Dependency d) {
                          ...
                      }
                  }
                  

                  通过 Foo 测试:

                  public class FooTest {
                      @Test
                      public void dependencyIsNotCalled() {
                          final Foo foo = new Foo(...);
                          final Dependency dependency = mock(Dependency.class);
                          foo.bar(dependency);
                          **// verify here that someMethod was not called??**
                      }
                  }
                  

                  推荐答案

                  更有意义:

                  import static org.mockito.Mockito.never;
                  import static org.mockito.Mockito.verify;
                  
                  // ...
                  
                  verify(dependency, never()).someMethod();
                  

                  这里有这个功能的文档 §4 "验证调用的确切数量/至少 x/never",并且 never javadoc 是 这里.

                  The documentation of this feature is there §4 "Verifying exact number of invocations / at least x / never", and the never javadoc is here.

                  这篇关于如何验证没有使用 Mockito 调用特定方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 Java 中模拟文件 - 模拟内容 - Mockito 下一篇:Mockito.any() 通过泛型接口

                  相关文章

                  最新文章

                • <i id='3lpZG'><tr id='3lpZG'><dt id='3lpZG'><q id='3lpZG'><span id='3lpZG'><b id='3lpZG'><form id='3lpZG'><ins id='3lpZG'></ins><ul id='3lpZG'></ul><sub id='3lpZG'></sub></form><legend id='3lpZG'></legend><bdo id='3lpZG'><pre id='3lpZG'><center id='3lpZG'></center></pre></bdo></b><th id='3lpZG'></th></span></q></dt></tr></i><div id='3lpZG'><tfoot id='3lpZG'></tfoot><dl id='3lpZG'><fieldset id='3lpZG'></fieldset></dl></div>
                • <small id='3lpZG'></small><noframes id='3lpZG'>

                  <legend id='3lpZG'><style id='3lpZG'><dir id='3lpZG'><q id='3lpZG'></q></dir></style></legend><tfoot id='3lpZG'></tfoot>

                    • <bdo id='3lpZG'></bdo><ul id='3lpZG'></ul>