0
メインクラスには1つのint型と4つの文字列が含まれています。 データベースの挿入機能をテストします。下のコードを実行すると、 "junit.framework.AssertionFailedError"が失敗します。 元のクラスのデータ型を5つの文字列に変換してテストすると、うまくいきます.2つの異なるArgumentCaptorクラスが存在する可能性があると考えました。同じテストで2つの異なる引数キャプチャクラスを使用する方法
@Test
public void HappyTest2() throws SQLException, DAOException{
when(conn.prepareStatement(anyString())).thenReturn(psmt);
ArgumentCaptor<Integer> integercaptor = ArgumentCaptor.forClass(Integer.class);
ArgumentCaptor<String> Stringcaptor = ArgumentCaptor.forClass(String.class);
Product p = new Product(1);
p.setType("myType");
p.setManufacturer("myManufacturer");
p.setProductionDate("myProductionDate");
p.setExpiryDate("myExpiryDate");
testingDAO.insertProduct(p);
verify(psmt, times(1)).setInt(anyInt(), integercaptor.capture());
Assert.assertTrue(integercaptor.getAllValues().get(0).equals(1));
verify(psmt, times(4)).setString(anyInt(), Stringcaptor.capture());
Assert.assertTrue(Stringcaptor.getAllValues().get(1).equals("myType"));
Assert.assertTrue(Stringcaptor.getAllValues().get(2).equals("myManufacturer"));
Assert.assertTrue(Stringcaptor.getAllValues().get(3).equals("myProductionDate"));
Assert.assertTrue(Stringcaptor.getAllValues().get(4).equals("myExpiryDate"));
}
合格! 私はちょうどget(int)文がSQL文中の同じ入力の位置を参照していると考えていましたが、それは各引数キャプタに対してリセットされたようです ありがとう! – Shaman