[英]Making a unit test (c#) in Visual Studio 2010. What I'm doing wrong? The test fails always
我有一个表单:FormPrincipal.cs
在这种形式中,有一个名为InsertionSort()的公共方法,它接受2个参数:一个int [] (表示一个整数列表)和一个表示列表大小(元素数)的int 。 此函数只使用算法“插入排序”对列表进行排序
该方法不返回任何内容(因为在我的应用程序的逻辑中,列表只是ordened,而数组是一个点,然后原始列表被修改为正确的顺序)。
我正在尝试测试函数是否对列表进行排序。
我在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");
}
我想这可能取决于InsertionSort()不会返回任何东西,但Visual Studio不会给出错误,也不会打印任何消息(例如“ordered”或“NOT ordered”)。
我运行时测试失败了
感谢您的任何帮助
删除Assert.Inconclusive("A method that does not return a value cannot be verified.");
。
这基本上告诉VS你没有实现你的测试。
当你有一个数组时,你可以简单地使用array.Length
来获得数组的大小,不需要传递大小。
您的排序算法不属于表单类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.