簡體   English   中英

參數匹配器的使用無效! 0匹配預期,1記錄

[英]Invalid use of argument matchers! 0 matchers expected, 1 recorded

雖然錯誤是非常具有描述性的,但我無法理解它。 對於線條:

    PowerMockito.when(
            mockStringMessageService.lookupString(Matchers.eq("XYZ")))
            .thenReturn(Matchers.eq("XYZ"));

錯誤是:

[junit] Invalid use of argument matchers!
[junit] 0 matchers expected, 1 recorded:
[junit] -> at com.amazon.kilvish.types.StatusTableTest.setUp(StatusTableTest.java:61)
[junit] 
[junit] This exception may occur if matchers are combined with raw values:
[junit]     //incorrect:
[junit]     someMethod(anyObject(), "raw String");
[junit] When using matchers, all arguments have to be provided by matchers.
[junit] For example:
[junit]     //correct:
[junit]     someMethod(anyObject(), eq("String by matcher"));
[junit] 
[junit] For more info see javadoc for Matchers class.

為什么期望0匹配器?

您不能在thenReturn子句中使用匹配器。 只需使用字符串文字:

PowerMockito.when(
        mockStringMessageService.lookupString(Matchers.eq("XYZ")))
        .thenReturn("XYZ");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM