我试图捕获在输入传递到与PowerMockito模拟对象的参数,这是代码: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(任何,捕捉参数);”
出了什么问题?
是的,你是对的,我把验证后,它的工作原理,但我想念它是如何工作的。 如果我把测试执行后的方法验证模拟知道它必须捕获参数? – user2572526
我不确定PowerMockito的内部,但它应该记录所有调用模拟方法的参数 – chomnoue