dimanche 8 mars 2015

MSUnit Assert not Working

Everything is working on MSUnit except my Assert, I checked and found that it's a bit different in MSUnit than nUnit, went through a blog post and doing exactly same but still getting error while debugging the test.


When I check my ex in the Unit Test (after throwing the error), the message I get is "error in the application", which fails the test as the expected message is different


Any Ideas?



[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");
}
}

Aucun commentaire:

Enregistrer un commentaire