Thursday, March 10, 2011

Unit Testing with XUnit.net 1.7


Introduction

xUnit.net is a testing framework which is simple to use for .net developers. It comes with a testing framework library and Test runners for .net 2.0 and 4.0.

Implementation

  1. Download the xUnit.net framework from here and install it.

    image

  2. Add a Visual Studio Class Library Project and name it as Calculate.Test

    image

  3. Add reference to the Project that need to test.
  4. Add reference to xUnit dll. The solution structure will looks like this.  

    image

  5. Open CalculateTest.cs file write a test method for Add method in the Calculate Project.

    Let’s try for a fail case

    image

  6. Open xUnit.net Test Runner application from installation folder

    image

  7. Select Open from Assembly menu and add the test dll i.e Calculate.Test.dll which will be displayed in xUnit.net Test Runner as shown below

    image

  8. Click the Run All button to execute the test methods and the results will be displayed as shown below. 

    image 

  9. Modify the test case as shown below to fix the test case

    image

  10. Run the test will give the green signal.

    image

Conclusion

xUnit.net is a easy to use framework for .net developers.

Thanks,
Bimal

No comments:

Post a Comment