Using the VS testing framework, I am now writing my tests as follows:
[TestMethod]
public void TestSomething()
{
try
{
var someTestValue = _someTestClass.SomeTestMethod();
Assert.IsNotNull(someTestValue);
}
catch (Exception e)
{
Assert.Fail(e.Message);
}
}
My logic is that if an exception is thrown in SomeTestMethod(), I will immediately end the test displaying the exception message through Assert.Fail(e.Message).
"Normal way" of actions:
[TestMethod]
public void TestSomething()
{
var someTestValue = _someTestClass.SomeTestMethod();
Assert.IsNotNull(someTestValue);
}
Is my approach right or is this the normal way? Am I writing redundant code?
source
share