【发布时间】:2020-04-14 17:17:00
【问题描述】:
如何在 c# 中编写单元测试(使用 nUnit)一个具有不带参数的方法的类? 我在 Program.cs 中调用这个 showinfo() 方法。我想为此编写一个 nunit 测试用例……但由于它不包含任何参数,我该如何测试它?
public void showInfo() //no arguments are passes here and im calling this in Program.cs
{
int indexNum;
string inId = Convert.ToString(Console.ReadLine());//taking Id as input
Console.Write("Enter account Password :");
string inPass = Convert.ToString(Console.ReadLine());//taking password
if (myId.Contains(inId)&&myPass.Contains(inPass))
{
Console.ForegroundColor= ConsoleColor.Green;
Console.WriteLine("Login Success!", Console.ForegroundColor);
Console.ResetColor();
indexNum = Array.IndexOf(myId, inId);
Console.WriteLine("Your details: ");
Console.WriteLine("Name: " + myName[indexNum]);
Console.WriteLine("Id: " + myId[indexNum]);
Console.WriteLine("Acc Type: " + myAccType[indexNum]);
Console.WriteLine("Date of Joining: " + myDob[indexNum]);
Console.WriteLine("Domain: " + myDomain[indexNum]);
Console.WriteLine("Manager: " + myManager[indexNum]);
//Console.WriteLine("Employee name: " + empl_name[indexNum]);
//Console.WriteLine(myId);
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Login Error!",Console.ForegroundColor);
Console.ResetColor();
}
}
【问题讨论】:
标签: c# unit-testing testing nunit