Iは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. */
Iテストを実行すると、私はラインMockito.verify(モック)を実行例外を有します.put(...);
"募集していますが呼び出されていないmock.put(any、キャプチャ引数);"
どうしたのですか?
はい、あなたは正しいです、私は後に検証を入れて、それは動作しますが、私はどのように動作するのか迷っています。 メソッドを検証して実行をテストしたら、模擬的にパラメータを取得する必要があることがわかりますか? – user2572526
PowerMockitoの内部についてはわかりませんが、モックのメソッドへのすべての呼び出しをパラメータで記録する必要があります – chomnoue