<small id='9MR9T'></small><noframes id='9MR9T'>

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

        <legend id='9MR9T'><style id='9MR9T'><dir id='9MR9T'><q id='9MR9T'></q></dir></style></legend>

      1. <tfoot id='9MR9T'></tfoot>

        查找 Mockito 构造的导入静态语句

        时间:2023-09-25

      2. <i id='sl1uL'><tr id='sl1uL'><dt id='sl1uL'><q id='sl1uL'><span id='sl1uL'><b id='sl1uL'><form id='sl1uL'><ins id='sl1uL'></ins><ul id='sl1uL'></ul><sub id='sl1uL'></sub></form><legend id='sl1uL'></legend><bdo id='sl1uL'><pre id='sl1uL'><center id='sl1uL'></center></pre></bdo></b><th id='sl1uL'></th></span></q></dt></tr></i><div id='sl1uL'><tfoot id='sl1uL'></tfoot><dl id='sl1uL'><fieldset id='sl1uL'></fieldset></dl></div>
      3. <legend id='sl1uL'><style id='sl1uL'><dir id='sl1uL'><q id='sl1uL'></q></dir></style></legend>
          1. <tfoot id='sl1uL'></tfoot>
              • <bdo id='sl1uL'></bdo><ul id='sl1uL'></ul>
                    <tbody id='sl1uL'></tbody>

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

                  本文介绍了查找 Mockito 构造的导入静态语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正试图冲破我和 Mockito 之间的砖墙.试图为 Mockito 的东西获取正确的 import static 语句时,我已经把头发扯掉了.你会认为有人会扔一张桌子说 anyInt() 来自 org.mockito.Matcherswhen() 来自org.mockito.Mockito 等等,不过这对新手来说太有帮助了,不是吗?

                  I'm trying to crash through the brick wall between me and Mockito. I've torn my hair out over trying to get correct import static statements for Mockito stuff. You'd think someone would just throw up a table saying that anyInt() comes from org.mockito.Matchers and when() comes from org.mockito.Mockito, etc., but that would be too helpful to newcomers, no?

                  这种事情,尤其是与无数以星号结尾的导入语句混合时,并不总是很有帮助:

                  This sort of thing, especially when mixed in with myriad more import statements ending in asterisks, isn't always very helpful:

                  import static org.junit.Assert.*;
                  import static org.mockito.Mockito.*;
                  

                  是的,我知道并一直在尝试使用 Eclipse Window -> Preferences-> Java -> Editor-> Content Assist -> Favorites 机制.它有帮助,但不会一针见血.

                  Yes, I know about and have been trying to use the Eclipse Window -> Preferences-> Java -> Editor-> Content Assist -> Favorites mechanism. It helps, but it doesn't hit the nail on the head.

                  对此问题的任何答案将不胜感激.

                  Any answers to this question would be appreciated.

                  非常感谢,拉斯

                  推荐答案

                  问题是静态导入从 Hamcrest 和 Mockito 名称相似,但分别返回 Matchers 和实数值.

                  The problem is that static imports from Hamcrest and Mockito have similar names, but return Matchers and real values, respectively.

                  一种解决方法是简单地复制 Hamcrest 和/或 Mockito 类并删除/重命名静态函数,以便它们更容易记住并且更少出现在自动完成中.我就是这么做的.

                  One work-around is to simply copy the Hamcrest and/or Mockito classes and delete/rename the static functions so they are easier to remember and less show up in the auto complete. That's what I did.

                  另外,在使用 mocks 时,我尽量避免使用 assertThat 以支持其他其他 assertionsverify,例如

                  Also, when using mocks, I try to avoid assertThat in favor other other assertions and verify, e.g.

                  assertEquals(1, 1);
                  verify(someMock).someMethod(eq(1));
                  

                  而不是

                  assertThat(1, equalTo(1));
                  verify(someMock).someMethod(eq(1));
                  

                  如果您从 Eclipse 的收藏夹中删除类,并输入长名称,例如org.hamcrest.Matchers.equalTo 并按 CTRL+SHIFT+M 来添加导入",然后自动完成只会显示 Hamcrest 匹配器,而不显示任何 Mockito 匹配器.只要您不混合匹配器,您就可以通过其他方式执行此操作.

                  If you remove the classes from your Favorites in Eclipse, and type out the long name e.g. org.hamcrest.Matchers.equalTo and do CTRL+SHIFT+M to 'Add Import' then autocomplete will only show you Hamcrest matchers, not any Mockito matchers. And you can do this the other way so long as you don't mix matchers.

                  这篇关于查找 Mockito 构造的导入静态语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何使用 mockito 测试 REST 服务? 下一篇:如何解决不必要的存根异常

                  相关文章

                  最新文章

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

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

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

                • <legend id='NLxy1'><style id='NLxy1'><dir id='NLxy1'><q id='NLxy1'></q></dir></style></legend><tfoot id='NLxy1'></tfoot>