Unit Testing – Test Driven Development (TDD) – NUnit

Posted: November 22, 2010 in VS 2010
Tags: , ,

Test-driven development requires developers to create automated unit tests that define code requirements (immediately) before writing the code itself. The tests contain assertions that are either true or false. Passing the tests confirms correct behavior as developers evolve and refactor the code. Developers often use testing frameworks, such as xUnit, NUnit … etc to create and automatically run sets of test cases.

Assemble Activate Assert or Arrange Act Assert is a good Pattern to follow as part of Unit Testing in TDD.

  • All TestCases first Assemble the data resources they intend to use.
  • Then they Activate a target method. (Preferrably the one you name your real test case after!)
  • Then they Assert that some side-effect, from that method, is within tolerance.

Visual Studio – supports built-in testing capabilities for following different types of tests. QAs can install Visual Studio Test Edition and can use Test Project for their testing. Use Test List Editor for selecting/running different tests.

  • Unit Test/Unit Test Wizard – helps in creating new Unit test for a class file. This will be helpful for both developers and testers to perform unit level testing.
  • Coded UI Test – used for recording the UI activities of a manual test. 
  • Database Unit Test – used for testing stored procedures and functions.
  • Generic Test – is for wrapping an executable as a test method. You can wrap the executable using generic Test and can include the same in test automation.
  • Ordered Test – is for executing multiple test scripts in a particular order. 
  • Web Performance Test – used for recording the URLs and generating the code for performance testing.
  • Load Test – is used for performing load test on an application. It simulates multiple users as virtual users and executes the test scripts to simulate the real user load on different servers like Application Server, Database server and Web server. Load test can be used with any of the test scripts. 
  1. Namespace – Microsoft.VisualStudio.TestTools.UnitTesting, Assembly – Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
  2. Few Main attributes – [TestClass], [Owner(“VJ”)], [TestMethod], [ExpectedException(typeof(ContractException), “SongId must be positive number”)]

NUnit –

  1. Uses Constraint-based modal.
  2. NUnit.Framework is the main namespace
  3. Following are the few main attributes used in many test cases …
    • [TestFixture], [SetUp], [Test], [ExpectedException(typeof(InsufficientFundsException))], [Ignore(“Decide how to implement transaction management”)], [Category(“LongRunning”)], [Culture(“fr-FR”)]
  4. Following are the main assertions used in Constraint based modal
    • Equality (Assert.AreEqual/.AreNotEqual), Condition (Assert.IsTrue/IsNull/IsEmpty/IsNan), Comparison (Assert.Greater/GreaterOrEqual/Less/LessOrEqual)

References

More about TDD refer http://en.wikipedia.org/wiki/Test-driven_development

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s