0
除了我的Assert之外,一切都在MSUnit上进行,我检查并发现MSUnit与nUnit有点不同,它经历了一篇博客文章,完全一样,但在调试测试时仍然出现错误。MSUnit Assert not Working
当我检查我在单元测试EX(引发错误后),我得到的消息是“错误的应用程序”,其中未通过测试的预期消息是不同
什么想法?
[TestMethod]
[ExpectedException(typeof(InvalidAreaException))]
public void GetAreaWithNegativeValueTest()
{
try
{
Utility.GetArea(2, -1, 2);
}
catch (InvalidAreaException ex)
{
Assert.AreEqual ("Inputs must be positive numbers", ex.Message);
throw;
}
}
//Exception Class
public class InvalidAreaException : ApplicationException, ISerializable
{
public string msg;
public InvalidAreaException(string message)
{
//msg = message;
}
}
//Actual Method to be tested
public static double GetArea(int arg1, int arg2, int arg3)
{
double area = 0d;
if ((arg1 < 0) || (arg2 < 0) || (arg3 < 0))
{
throw new InvalidAreaException("Inputs must be positive numbers");
}
}
你的GetArea方法没有返回语句,这甚至编译? – Paolo 2015-03-08 17:35:34
它不叫MSUnit它被称为MSTests框架,无论如何尝试从方法中删除try/catch:“GetAreaWithNegativeValueTest”,因为你想方法来检测异常的权利? – 2015-03-08 17:35:39
我会检查你的单元测试。一个好的测试应该只有一条路径通过代码(否则你冒着测试本身的逻辑问题)。这样做可能会指出你的问题。 – 2015-03-08 17:36:41