[英]Easymock matcher on return value
foo.toString()返回
"[id: <id>, stuffIdontCareAbout: 0]"
我想測試id是否正確,但是字符串中的其他所有值都可以具有任何值。 這是我嘗試的:
expect(foo.toString()).andReturn(EasyMock.find("[id: 42,"));
但是這是它抱怨的方式:
java.lang.IllegalStateException: 0 matchers expected, 1 recorded.
This exception usually occurs when matchers are mixed with raw values when recording a method:
foo(5, eq(6)); // wrong
You need to use no matcher at all or a matcher for every single param:
foo(eq(5), eq(6)); // right
foo(5, 6); // also right
那么,如何在返回值上使用EasyMock匹配器?
這聽起來不像是一個模擬。 看來您只想測試foo.toString()
的結果。
使用AssertJ(建議使用)意味着
assertThat(foo.toString()).startsWith("[id: 42,");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.