NUnit
is a open source framework.We can write automated tests to test our .Net code
using the NUnit framework. NUnit does not create any test scripts by
itself. We have to write test scripts by ourselves, but NUnit allows us to use
its tools and classes to make unit testing easier.
Automated testà
1.Find defects earlier in development
lifecycle thus reduced business cost.
2.Makes user happy as fewer defect reach
in production environment.
3.Development team get more time to add
new feature.
4.Reliable as same test code runs each
time
5.Quicker
than a human performing tests manually
Features of NUnità
1.Tests can be run from a console runner,
within Visual Studio through a Test Adapter. The console runner works through the NUnit Test Engine, which provides
it with the ability to load, explore and execute tests.
2.Tests can be run in parallel.
3.Follows strongly TDD
4.Assertion tell the test runner whether
test has passed and failed
Attributes of NUnità
1.TestFixtureAttribute [TestFixture]
TestFixture attribute assigns a class that contains tests
and optionally, setup or teardown methods.
2.TestAttribute [Test]
The [Test] attribute is a way to mark method inside a [TextFixture] class as test
method. NUnit will recognize inline method as test method and execute that.
3. SetupAttribute
[SetUp]
This attribute is to mark a method inside
[TestFixture] class which we want to execute before executing each Test method.
If there is more than one test, then setup method will execute just before
executing the test.
4.TearDownAttribute [TearDown]
This attribute is to mark a method inside
[TestFixture] class which we want to execute after executing each Test method.
Once SetUp and Test are executed, TearDown test is executed. If you have more
than one test, they will be executed in the following order;
As long as SetUp method runs without any error, it is
guaranteed that TearDown test will execute. It will not run if Setup throws an
Exception.
NUnit Assertionsà
NUnit provides various set of assertions.Here are some
of them.
#Assert.AreEqual(expected, actual)
#Assert.AreNotEqual(expected, actual)
#Assert.AreSame(expected, actual)
#Assert.NotSame(expected, actual)
#Assert.Greater(arg1, arg2)
#Assert.Less(arg1, arg2)
#Assert.IsTrue(aBool)
#Assert.IsFalse(aBool)
#Assert.IsEmpty(aString)
#Assert.IsNotEmpty(aString)
#Assert.Fail()
#Assert.Fail()
Comments
Post a Comment