Friday, April 18, 2008

NUnit basics for new bees

In smaller to bigger project, here are some basics about how to automate Unit testing with NUnit framework on .Net Platform.

Where NUnit spot on SDLC?
In other words, we can ask when to start unit automation on project? It depends on various parameters say for example Complexity of Method(s) / API(s) or Classes in production cycle - How Method(s) API(s) / Classes are called by other Method(s) / API(s) / Classes in production cycle.


We can start NUnit automation after completion of any independent Method / API / its Class created at production and making automation continued towards parallel of development cycle of more dependent Method(s) / API(s) / Classe(s).

Say for example we have small class library project in C#.









Now lets start NUnit Automation in 7 simple steps :

  1. Create New Test C# Project (Here Named TestProject) and add production class (.dll) reference.
  2. Add reference NUnit.Frameworkto the TestProject.
  3. Add attribute "TestFixture" to mark as Test Class and so NUnit GUI can recognize.
  4. To create Test Category / Test-Cases group, add attribute “Category” passing with CategoryName as a param say for here [Category(“TestCategory1”)].
  5. Add attribute “Test”to the test-cases which will teardown inside test-class.
  6. To implement test-case , create Object of the AUT Class and call Assert with its various methods as required.
  7. Save the project and Open this on NUnit GUI and last run the test.

Njoy, Nimesh - (Get more NUnit stuff on http://www.nunit.org )

1 comment:

Popular Posts