I'm learning VS Unit test and tried this:
[TestMethod()]
public void calcTest()
{
double expected = 1.234F; // TODO: Initialize to an appropriate value
double actual;
actual = 1.234F;
Assert.AreEqual(expected, actual);
Assert.Inconclusive("Verify the correctness of this test method.");
}
When running this test method, it says inconclusive ??? Why ?
Update: Ok to tell don't compare floats, but business requirements are what they are. So what should I do if I need to compare them?
Do you mean it's impossible to test floating calculation without headache? Then if testing is such a headache in financial calculation isn't it better to not do testing at all?
Seems like a huge bug or design flaw in vs test framework rather :) as it is said here http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.assert.inconclusive%28VS.80%29.aspx
Indicates that an assertion cannot be proven true or false.
Since I compare 2 same litterals sure it is true.
erm, because you told it to be?
Assert.Inconclusive("Verify the correctness of this test method.");
Now you have your AreEqual
, you should be able to remove this Inconclusive
Any failure during a test (not including exceptions that you intentionally handle) is generally terminal, but any assert that passes (like the AreEqual
here) just keeps on running. So the first test passes, then the last line flags it as inconclusive.
Even when you've removed the Assert.Inconclusive
you still might have problems.
You're testing the equality of two floating point numbers and in general with calculated values you'll never get them exactly the same. You need to check that the actual value is within an acceptable range of the expected value:
Math.Abs(actual - expected) < 0.00001;
for example.
Your Assert.AreEqual(expected, actual);
works in this case because you are assigning the same value to both variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With