Skip to main content

Getting started NUnit


  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;
 SetUp > Test1 > TearDown > SetUp > Test2 > TearDown
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()

Comments

Popular posts from this blog

JIRA OverView

What is JIRA? JIRA is a project management tool used for issues and bugs tracking system for all types of testing.The JIRA dashboard consists of many useful functions and features which make handling of issues easy. The following points explain some interesting details of JIRA. • JIRA is an incident management tool. • JIRA is not an acronym, the name 'JIRA' comes from the Japanese word 'Gojira' • JIRA is developed by Australian Company Atlassian • JIRA is a platform independent tool; it can be used with any OS. • JIRA is multi-lingual tool − English, French, German, Japanese, Spanish, etc. • JIRA can be integrated with many other tools like GitHub, Team Foundation Software and many more. • JIRA is a commercial tool and available as a Trial version for a limited time. • To utilize JIRA services, a license is required. Features: JIRA is one the best product management tool which includes: Issue tracking & management: A software application that allows to