我正在使用单元测试进行实验性实验,下面是我正在测试的应用程序的一段代码。大多数单元测试已完成,但关于下面的构造函数,我无法弄清楚如何测试它。例如,构造函数是如何处理数组元素的?什么是测试顾问的好方法?构造函数的单元测试
有没有可能给我一个正确的方向踢一个善良的灵魂?
public struct Point {
public int x, y;
public Point(int a, int b) {
x = a;
y = b;
}
}
...
public Triangle(Point[] s) {
sides = new double[s.Length];
sides[0] = Math.Sqrt(Math.Pow((double)(s[1].x - s[0].x), 2.0) + Math.Pow((double)(s[1].y - s[0].y), 2.0));
sides[1] = Math.Sqrt(Math.Pow((double)(s[1].x - s[2].x), 2.0) + Math.Pow((double)(s[1].x - s[2].x), 2.0));
sides[2] = Math.Sqrt(Math.Pow((double)(s[2].x - s[0].x), 2.0) + Math.Pow((double)(s[2].x - s[0].x), 2.0));
}
...
[TestMethod()]
public void TriangleConstructorTest1()
{
Point[] s = null; // TODO: Initialize to an appropriate value
Triangle target = new Triangle(s);
Assert.Inconclusive("TODO: Implement code to verify target");
}
你确定他们需要你也测试构造吗?对我来说似乎毫无意义,因为你只是在做一些任务。 – Tudor 2012-01-05 17:24:48
以任何方式暴露“双方”? “Triangle”有哪些公共属性? – 2012-01-05 17:25:17
@Tudor:其实我倾向于不同意。因为它在做任务,所以它可能应该进行单元测试,以确保它分配预期的内容。但那仅仅是我的0.02美元,而且每个人都以不同的方式处理单元测试。 – 2012-01-05 17:27:03