從我這個問題的認識,我不認爲你需要有一個GUI測試工具在這裏。
有我的簡單的測試思路:
- 創建一個實例AttributeColumnGenerator。
- 創建一個表格。
- 將項添加到表
- 使用columnId和itemId調用
generateCell
。
- 對該方法返回的Component執行適當的斷言。
這裏是我的想法
首先的一個片段我ColumnGenerator
誰只創建一個單元格的值的標籤。
public class AttributeColumnGenerator implements Table.ColumnGenerator {
public Object generateCell(Table source, Object itemId, Object columnId) {
String textToDisplay = (String)source.getItem(itemId).getItemProperty(columnId).getValue();
return new Label(textToDisplay);
}
}
而且測試方法
@Test
public void attributeColumnGenratortest()
{
AttributeColumnGenerator columnGenerator = new AttributeColumnGenerator();
Table table = new Table();
String columnId = "test";
table.addContainerProperty(columnId, String.class, "");
String itemId = "item1";
Item item = table.addItem(itemId);
item.getItemProperty(columnId).setValue("Value of item1");
Label generateObject = (Label)columnGenerator.generateCell(table, itemId, columnId);
// Assert any properties of the returned Component.
// In this snippet, I only printOut the boolean comparaison.
System.out.println("Value of item 1".equals(generateObject.getValue()));
}
也許它不是最好的解決辦法,但它的作品。
希望它的幫助!
問候。
謝謝你,事情是我在很長的邏輯單元創建我的對象類型,以及我處理此表的數據。當它自然被調用時,會自動調用所有項目和屬性。如果我手動撥打電話,我能夠僅對該特定項目進行測試嗎? – Spring
@Spring是的,你正在測試一個指定項目。您將表格作爲generateCell方法的參數,因此您可以訪問任何項目。我認爲用兩個嵌套的foreach可以測試任何具有任何屬性的項目。例如:for(Item item:table.getItemsId){for(Object propertyId:table.getContainerPropertyIds()){}} – 2012-05-03 09:33:50