我是新來的Android的測試,並已決定通過實例的Mockito從http://docs.mockito.googlecode.com/hg/latest/org/mockito/Mockito.html#3參數匹配不驗證參數
工作要充分認識發生了什麼事情開始,我已經決定從分支出來例如,這是我的代碼:
@Test
public void testMatchers() throws Exception
{
LinkedList <String> mockedList = mock (LinkedList.class);
when (mockedList.contains(argThat(isValidStr()))).thenReturn(true);
System.out.println(mockedList.contains("Asdf")); // prints 'true', as expected
System.out.println(mockedList.contains("asdf")); // prints 'true' which I guess makes sense... but shouldn't the argument matcher complain somehow?
}
public static ArgumentMatcher<String> isValidStr()
{
return new ArgumentMatcher<String>()
{
@Override
public boolean matches (Object argument)
{
String str = (String) argument;
return (str.charAt(0) > 'A' || str.charAt(0) < 'Z') // if first letter is capitalized
}
}
}
所有測試都通過,有0個例外/錯誤。另外,我在「匹配」功能的開始處放置了一個斷點,並且它永遠不會被擊中。
3個問題: 1)爲什麼我的參數匹配器不抱怨錯誤的爭論?
2)檢測到錯誤的參數後,預期的輸出是多少? 3)代碼如何看起來像檢測一個不合適的參數?