NUnit is a Nunit-testing framework for all .Net languages.You can download it from http://www.nunit.org. The NUnit framework is developed from ground up to make use of .NET framework functionalities. It uses an Attribute based programming model. It loads test assemblies in separate application domain hence we can test an application without restarting the NUnit test tools. The NUnit further watches a file/assembly change events and reload it as soon as they are changed. With these features in hand a developer can perform develop and test cycles sides by side.
we should understand what NUnit Framework is not:
* It is not Automated GUI tester.
* It is not a scripting language, all test are written in .NET supported language e.g. C#, VC, VB.NET, J# etc.
* It is not a benchmark tool.
* Passing the entire unit test suite does not mean software is production ready.
The Main Concepts in the Unit testing is:
1. Text Fixtures.
2. Test Cases.
Test Fixtures:
A Test fixture is used to group and run multiple tests that test a logical collection of functionality. Programmatically, a test fixture corresponds to a class that in turn contains unit tests as methods of the class. A Test Fixture class must have either a public default constructor or no constructor, which implicitly creates a public default constructor. Identify a class as a test fixture by decorating it with the [TestFixture] attribute.
Example Declaration of a Texture:
using System;
using NUnit.Framework;
namespace example.namespace
{
[TestFixture]
public class ExampleTestFixture
{
[Test]
public void TestExample()
{
// Your test here
}
[Test]
public void TestExample2()
{
// Your second test here
}
// etc...
}
}
Test Cases:
Test is the lowest building block of unit testing and tests a single piece of software functionality. Programmatically, a test corresponds to a method in the unit test code. You identify a test by decorating a method with the [Test] attribute.
Each test case will consist of three parts. The first part sets up the test by instantiating "Tester" objects that know how to parse ASP.NET. The second part loads the page from the web server, and the third part performs the test by using and making assertions about the testers.
Example Declaration of a Test Case:
[Test]
public void TestExample()
{
// First, instantiate "Tester" objects:
LabelTester label = new LabelTester("textLabel");
LinkButtonTester link = new LinkButtonTester("linkButton");
// Second, visit the page being tested:
Browser.GetPage("http://localhost/example.aspx");
// Third, use tester objects to test the page:
Assert.AreEqual("Not clicked.", label.Text);
link.Click();
Assert.AreEqual("Clicked once.", label.Text);
link.Click();
Assert.AreEqual("Clicked twice.", label.Text);
}
No comments:
Post a Comment