Tuesday, March 10, 2009

Unit testing in Visual Studio 2008 Team System - part III

In previous post Unit testing in Visual Studio 2008 Team System - part II I’ve described how to perform units tests using new test functionality in VS2008 TS.

In this part I will continue describing test functionality (base on nUnit guide’s example)


In Part II I’ve showed how to use Assert methods to evaluate tests.

Asert() is not only one way to perform tests. Units testing gives also possibility to examine if expected exception occurred.


Let’s return to nUnit example.

[ExpectedException(typeof(InsufficientFundsException))]


If we assume that minimum acceptable account’s balance can be 10F, and if balance is less custom exception (named “InsufficientFundsException“) will be throw.

In that case we can add attribute to our test method informing that we expecting exception:
[ExpectedException(typeof(InsufficientFundsException))]


So, we need to archive this is


1) implement own Exception class:

public class InsufficientFundsException : ApplicationException {}


2) correct orrect our test method:






3) correct our production Account.TransferFunds() method:









Labels:

1 Comments:

Anonymous Anonymous said...

nic post
http://mkniit.blogspot.in

July 5, 2016 at 7:29 AM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home