Java Mockito模拟调用点指向Junit代码(ParentRunner)

Java Mockito模拟调用点指向Junit代码(ParentRunner),java,unit-testing,junit,mocking,mockito,Java,Unit Testing,Junit,Mocking,Mockito,以前从未见过此问题-当使用verify或verifyInteractions且测试失败时,Mockito的职业列表指向JUnit代码,而不是应用程序代码: [junit]此处不需要交互: [junit]->位于org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) [junit]但在模拟的“mockCounter”上发现了此交互: [junit]->位于org.junit.runners.ParentRunner.runLeaf

以前从未见过此问题-当使用
verify
verifyInteractions
且测试失败时,Mockito的职业列表指向JUnit代码,而不是应用程序代码:

[junit]此处不需要交互:
[junit]->位于org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
[junit]但在模拟的“mockCounter”上发现了此交互:
[junit]->位于org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
[少年]***
[junit]以下是所有调用的列表供您参考([?]-表示未验证)。
[junit]1。[?]->位于org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
[junit]2。[?]->位于org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
[junit]3.->位于org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
[少年]
[junit]junit.framework.AssertionFailedError:
[junit]此处不需要交互:
[junit]但在模拟的“mockCounter”上发现了此交互:
[少年]***
[junit]以下是所有调用的列表供您参考([?]-表示未验证)。
我正在使用Mockito
1.10.19
和JUnit
4.12
。代码非常标准:

公共类MyTest{
@统治
public MockitoRule MockitoRule=MockitoJUnit.rule();
@嘲弄
私人柜台;
...
@试验
公开无效测试(){
...
验证Nomore交互(模拟计数器);
}
首先,我还使用了
ExpectedException
规则:

@规则
抛出公共ExpectedException=ExpectedException.none();
…这导致了其他问题,因为它将Mockito的验证失败捕获为意外异常:

[junit] No interactions wanted here:
[junit] -> at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
[junit] But found this interaction on mock 'mockCounter':
[junit] -> at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
[junit] ***
[junit] For your reference, here is the list of all invocations ([?] - means unverified).
[junit] 1. [?]-> at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
[junit] 2. [?]-> at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
[junit] 3. -> at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
[junit]
[junit] junit.framework.AssertionFailedError:
[junit] No interactions wanted here:
[junit] But found this interaction on mock 'mockCounter':
[junit] ***
[junit] For your reference, here is the list of all invocations ([?] - means unverified).
我正在开发一个新的代码库,以前从未见过这个问题。似乎Mockito或JUnit清除堆栈跟踪的力度太大或是其他什么


我可以在没有
ExpectedException
的情况下生活,但在未来测试失败的情况下没有模拟调用点似乎很烦人。我如何解决这个问题?我支持
withSettings()的概念。verboseLogging()
但我不想总是记录调用,除非测试失败。

似乎
MockitoRule
是罪魁祸首。用
MockitoAnnotations.initMocks(this);
in
setUp()
方法完全修复了问题,即使使用了
ExpectedException
规则

它一直在Mockito
2.x
中,但没有向后移植到
1.x