これは可能ですか?試してみましEasyMock.expectLastCall().times(0);
たが、EasyMockは時間が1以上でなければならないと文句を言います
6 に答える
使用できます.andThrow(new AssertionFailedError()).anyTimes();
-これはスローするのと同じ例外ですAssert.fail()
が、を作成するよりも冗長ではありませんAnswer
。
easymock 3.0では、expectLastCallに.anyTimes()を追加する必要があります。そうしないと、テストは失敗します。
Expectation failure on verify: myMethod(): expected: 1, actual: 0`
nkr1ptの例に基づく:
expectLastCall().andAnswer(new IAnswer() {
public Object answer() {
Assert.assertFail();
return null;
}
}).anyTimes();
The fact that some method is not called is controlled by Mock
or StrictMock
. They will throw an exception, when that not recorded method is called. This problem occurs only when using NiceMock
s, where default values are returned when calling for not recorded methods.
So a solution can be not to use NiceMock
s.
私にはバグのように見えます。内部クラスRange
では、最大値を1未満に設定することはできません。
そのメソッドをモックして、ただ呼び出すことができませんでしたAssert.fail()
か?
メソッドが呼び出されないことが予想される場合は、それを記録しないでください。しかし、私はそれが素敵なモックでは機能しないことに同意します。
私はなんとか解決策を思いついた:
expectLastCall().andAnswer(new IAnswer() {
public Object answer() {
Assert.assertFail();
return null;
}
});