【发布时间】:2018-03-07 11:17:43
【问题描述】:
我正在尝试使用 PowerMockito 捕获在输入中传递给模拟对象的参数,代码如下:
//I create a mock object
ClassMocked mock = PowerMockito.mock(ClassMocked.class);
//Create the captor that will capture the String passed in input to the mock object
ArgumentCaptor<String> argumentCaptor = ArgumentCaptor.forClass(String.class);
//When the method put is executed on my mock I want the second parameter (that is a String) to be captured
Mockito.verify(mock).put(anyString(), inputDataMapCaptor.capture());
//Creates the instance of the class that I want to test passing the mock as parameter
ClassToTest instance = new ClassToTest(mock);
//Executes the method that I want to test
instance.methodToTest();
/* I know that during the execution of "methodToTest()" mock.put(String,String) will be executed and I want to get the second string parameter. */
当我执行测试时,执行 Mockito.verify(mock).put(...); 行时出现异常
"想要但未调用 mock.put(any,Capturing argument);"
怎么了?
【问题讨论】:
标签: java unit-testing junit mockito powermockito