C#新手在这里。Max()函数的测试用例设计
据我所知,测试用例应该是:
- 简单透明
- 有最小的重复
- 保证100%的代码覆盖率
我也明白了边界值分析的基础知识和等价划分,但下面的函数,基本测试用例是什么?
static public int Max(int a, int b, int c)
{ // Lines of code: 8, Maintainability Index: 70, Cyclomatic Complexity: 4, Class Coupling: 0
if (a > b)
if (a > c)
return a;
else
return c;
else
if (b > c)
return b;
else
return c;
}
这是我迄今为止..
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ConsoleApplication10;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication10.Tests
{
[TestClass()]
public class ProgramTests
{
[TestMethod()]
public void MaxTestNulls(int a, int b, int c)
{
Assert.IsNotNull(a, "The first parameter must be present.");
Assert.IsNotNull(b, "The second parameter must be present.");
Assert.IsNotNull(c, "The third parameter must be present.");
}
[TestMethod()]
public void MaxTestTypes(int a, int b, int c)
{
Assert.IsInstanceOfType(a, typeof(int));
Assert.IsInstanceOfType(b, typeof(int));
Assert.IsInstanceOfType(c, typeof(int));
}
[TestMethod()]
public void MaxTestBasics(int a, int b, int c)
{
if (a > int.MaxValue || b > int.MaxValue || c > int.MaxValue)
{
Assert.Fail();
}
if (a < int.MinValue || b < int.MinValue || c < int.MinValue)
{
Assert.Fail();
}
}
}
}
我完全关闭基地在这里?我的老师不会鼓起并给我任何提示..我可以使用哪些其他测试用例会有用?
这非常有帮助,谢谢。还有一个问题,我将如何在单元测试中实现它?每当我尝试在我的TestMethods()中调用Max()时,它都会给出一个错误。 – dotKn0ck
我想我对实现感到困惑。 – dotKn0ck
@ dotKn0ck请参阅上面的测试方法实现。 –