我有一種形式:FormPrincipal.cs在Visual Studio 2010中進行單元測試(c#)。我在做什麼錯了?測試總是失敗
在這種形式中有一個名爲插入排序()服用2個參數的公共方法:一個INT [](表示整數列表)和INT代表列表的大小(元素數量)。 該函數只是使用算法「插入排序」來排序列表
該方法不會返回任何東西只是修改爲正確的順序)。
我試圖測試,如果功能排序列表。
我在Visual Studio中創建了一個單元測試(不是單獨的項目),但它總是說「失敗」而不顯示任何消息。我做錯了什麼? 的代碼是這樣的:
[TestMethod()]
public void InsertionSortTest()
{
FormPrincipal target = new FormPrincipal(<some parameters>);
target.loadData(); // function which load the list to be ordered
int[] list1 = new int[10];
list1 = {1,4,3,5,2,6,7,9,8,0);
target.InsertionSort(list1,10);
bool listaOrderedOrNot = isListOrdered(list1, 10); // isListOrder is just a function in the same file of the test where I loop the array checking if elements are growing.
Assert.Inconclusive("A method that does not return a value cannot be verified.");
// I tried to do the following assert command..
Assert.AreEqual(listaOrderedOrNot, true,"ordered");
Assert.IsTrue(listaOrderedOrNot, "ordered");
Assert.IsFalse(listaOrdenadaOrNot, "NOT ordered");
}
我想這可能取決於一個事實插入排序()不返回任何東西,但Visual Studio中沒有給出錯誤和消息(例如「命令」或「未訂購「)被打印。
測試,當我運行它
感謝您的幫助
謝謝。我已經完成了你告訴我的但是同樣的問題 – dragonmnl 2012-02-29 15:24:02
但是現在你應該得到一個「真實」的錯誤信息。也許你需要雙擊失敗的測試才能看到它。 – 2012-02-29 15:24:43
你是什麼意思?排序算法是FormPrincipal的一個公共方法 – dragonmnl 2012-02-29 15:25:56