在下面的程序创建单元测试下我可以编写什么代码来运行测试方法。 [英] What Will Be The Code I Can Write Under Create Unit Tests For The Below Program To Run Test Methods.
本文介绍了在下面的程序创建单元测试下我可以编写什么代码来运行测试方法。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
public class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter a");
int a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter b");
int b = Convert.ToInt32(Console.ReadLine());
Class1 obj = new Class1();
int c = 0;
obj.Add(a, b, out c);
Console.WriteLine(c);
Console.ReadLine();
}
public class Class1
{
public void Add(int a, int b, out int c)
{
c = a + b;
}
}
}
}
推荐答案
你可以编写NUnit测试方法(s)与通常使用NUnit完全相同的方式。基本思想是创建一个标有属性[TestFixture]
的类(或使用现有的类),并创建一些标记为的测试方法属性[Test]
然后使用该实用程序执行测试: NUnit - 快速入门 [ ^ ]。
-SA
You can write NUnit test method(s) in exact same way as it is usually done with NUnit. The basic idea is to create a class(es) (or use existing class(es)) marked with the attribute[TestFixture]
and create some test method(s) marked with the attribute[Test]
and then use the utility to perform the tests: NUnit — QuickStart[^].
—SA
这篇关于在下面的程序创建单元测试下我可以编写什么代码来运行测试方法。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文