2012-02-29 117 views
1

我有一种形式: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中没有给出错误和消息(例如“命令”或“未订购“)被打印。

测试,当我运行它

感谢您的帮助

回答

4

删除Assert.Inconclusive("A method that does not return a value cannot be verified.");只是失败。
这基本上告诉VS你没有实现你的测试。


当你有,你可以简单地使用array.Length得到数组大小的数组,就没有必要通过大小。


您的排序算法不属于表单类。

+0

谢谢。我已经完成了你告诉我的但是同样的问题 – dragonmnl 2012-02-29 15:24:02

+0

但是现在你应该得到一个“真实”的错误信息。也许你需要双击失败的测试才能看到它。 – 2012-02-29 15:24:43

+0

你是什么意思?排序算法是FormPrincipal的一个公共方法 – dragonmnl 2012-02-29 15:25:56

相关问题