开发者

How to check multiple condition check visual studio 2008 Unit Testing framework

I am work开发者_JAVA百科ing on creating unit test cases for few methods. I want to verify the return value and the out parameter for certain condition. If the conditions are met then perticular case will success else fail.

How to do this in Unit Testing Framework Visual Studio 2008.

Thanks, Omkar


Inside your unit test method, create an assertion for each test. For instance:

Assert.IsNotNull(returnValue);
Assert.IsTrue(anOutParameter > 0);

The test will only succeed if all the assertions succeed


I've no experience with Unit Testing Framework Visual Studio 2008 but with other Unit Testing frameworks, in order to perform multiple checks you simply Assert multiple times.

For example:

// Arrange
bool isValid;

// Act
string output = MyClass.SomeMethod(out isValid);

// Assert    
Assert.IsTrue(isValid);
Assert.Equals("test", output);


I'd recommend doing away with the out parameter.. Check if you need both return values. Especially if your return value is an error codes. Use exceptions over error code as it simplifies client code

string realReturnValue;
if(!MyMethod(out realReturnValue)
{
  //handle error
}

vs

var realReturnValue = MyMethod()

If you must have them, create a type that wraps [Result, OutputValue]. Define Equals on this type.

Assert.AreEqual(new ReturnType(true, "10"), valueReturnedByMethodCall)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜