在本節中,您將使用內容輔助來填寫共用迴圈結構的範本。 如果您尚未開啟 junit.samples/VectorTest.java 檔,請在 Java 編輯器中開啟它。
public void testValues() {
Integer[] expected= new Integer[3];
for
for 尾端,並按下 Alt+/,以啟用內容輔助。您將看到一個清單,列出 "for" 迴圈的共用範本。
當您按一下範本,或使用上移鍵或下移鍵選取範本時,您會在範本的說明訊息中看到其程式碼。請注意,會自動猜測本端陣列名稱。
for - iterate over array 項目,然後按下 Enter 鍵以確認範本。
這時範本將插入您的程式碼中。
for 迴圈:
for (int e= 0; e < expected.length; e++) {
expected[e]= new Integer(e + 1);
}
Integer[] actual= to
to 尾端,並按下 Alt+/,以啟用內容輔助。挑選 toarray - convert collection to array,並按下 Enter 鍵以確認選項(或按兩下選項)。
type 呈強調顯示並已選取。
Integer,以改寫選項。當您變更選項時,陣列建構子的類型也會隨之變更。
collection,然後輸入 fFull 來改寫它。
assertEquals(expected.length, actual.length);
for (int i= 0; i < actual.length; i++)
assertEquals(expected[i], actual[i]);
