【发布时间】:2016-11-18 21:54:44
【问题描述】:
这里是 C# 新手。
我理解测试用例应该是:
- 简单透明
- 重复次数最少
- 确保 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();
}
}
}
}
我完全不在这儿吗?我的老师不会鼓起勇气给我任何提示。。我还可以使用哪些其他测试用例有用?
【问题讨论】:
标签: c# unit-testing testing tdd