I am working on some unittest projects in VS 2008 in C#, i created one simple small method for unit test?
public int addNumber(int a, int b)
{
return a + b;
}
well i created a unit test method as below,
[TestMethod()]
public void addNumberTest()
{
Mathematical target = new Mathematical(); // TODO: Initialize to an appropriate value
int a = 4; // TODO: Initialize to an appropriate value
int b = 2; // TODO: Initialize to an appropriate value
int expected = 0; // TODO: Initialize to an appropriate value
int actual;
actual = target.addNumber(a, b);
Assert.AreEqual(expected, actual);
Assert.Inconclusive("Verify the correctness of this test method.");
}
But when i try to run the unittest project ,
I am receiving an Inconclusive message. My question is
- what exactly the Inconclusive is and when it comes into the picture?
- what are the necessary things, i need to do to make my unit test passed?
You need to decide what the criteria is for a unit test to be considered passed. There isn’t a blanket answer to what makes a unit test pass. The specifications ultimately dictate what constitutes a passing unit test.
If the method you are testing is indeed just adding two numbers, than the
Assert.AreEqual(expected,actual)is probably enough for this particular unit test. You may also want to checkAssert.IsTrue(expected>0)That may be another assertion you could tack on to this unit test.You’ll want to test it again though with other values like negatives, zeros, and really large numbers.
You won’t need the
Inconclusiveoperator for your unit tests of theaddNumbermethod. That assertion would be more useful when dealing with objects and threads possibly. Calling theInconclusiveassertion like you have will always fail and always return the string passed into it.