我正在使用單元測試進行實驗性實驗,下面是我正在測試的應用程序的一段代碼。大多數單元測試已完成,但關於下面的構造函數,我無法弄清楚如何測試它。例如,構造函數是如何處理數組元素的?什麼是測試顧問的好方法?構造函數的單元測試
有沒有可能給我一個正確的方向踢一個善良的靈魂?
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