【发布时间】:2020-04-18 18:18:54
【问题描述】:
我正在尝试进行测试以检查 View 返回正确的字符串。我对 NUnit 测试非常陌生,并且已经查看了一些教程,但我不确定我做错了什么。
using System;
namespace ItemTracker
{
public enum Category{Book,StorageDevice,Stationary};
class Item{
private string _id;
private double _price;
private Category _category;
public Item(string id, double price, Category category){
_id=id;
_price=price;
_category=category;
}
public string ID{
get{return _id;}
set{_id=value;}
}
public double Price{
get{return _price;}
set{_price=value;}
}
public Category Category{
get{return _category;}
set{_category=value;}
}
public string View(){
if(_category==Category.Book){
return "Get ready for the adventure!";
}
else if(_category==Category.StorageDevice){
return "Data storing in progress";
}
else if(_category==Category.Stationary){
return "Learn something new with me!";
}
else{
return "Invalid";
}
}
}
}
这是我的 TestClass.cs 和我已经尝试过的,即将输出的值放入数组中:
using NUnit.Framework;
using System;
namespace ItemTracker
{
[TestFixture()]
class testclass{
[Test()]
public void Testing(Item[] j){
j[0]=new Item("B1001",39.90,Category.Book);
foreach(Item x in j){
Assert.AreEqual("Get ready for the adventure!",x.View());
}
}
}
}
但是我收到一条错误消息:
Error Message:
No arguments were provided
【问题讨论】:
-
查看here 了解参数化测试。您需要添加注释(属性)来指定应如何传递参数。为什么不删除论点?你不需要它。在里面定义你的数组?
-
@OguzOzgul 哇,这救了我,谢谢
标签: c# unit-testing nunit