Saturday, February 21, 2015

Nunit Setup Environment in VisualStudio with Example Program



  • NUnit is a unit-testing framework for all .Net languages. 
  • It is written entirely in C# and has been completely redesigned to take advantage of many .NET language features, for example custom attributes and other reflection related capabilities.
  •  NUnit brings xUnit to all .NET languages.

To Setup Environment For NUnit follow the below Steps:

  • Download Nunit  from below URL: 
          Download Nunit


  

Click on Nunit-2.6.4.msi to download setup

  • Navigate to downloaded Nunit-2.6.4.msi and install.


Open Visual Studio File -> New -> Project-> Console Application



  • RightClick on solution Explorer and Add new class



Add Downloded Reference .dll files in the project 
To find Nunit Reference Library(.dll ) files navigate to installed folder

C:\Program Files (x86)\NUnit 2.6.4\bin\framework
  • Add reference library from solution explorer

Browse Librery



 
 C:\Program Files (x86)\NUnit 2.6.4\bin\framework
 

  Click OK.

Also add Selenium Webdriver Library click on below url.


After that add the below namespaces
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using NUnit.Framework;
 Note : In the below example i used ChromeDriver

Source code :


using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using NUnit.Framework;

namespace NunitTest
{
    [TestFixture]
    class Checkurl
    {
        [Test]
        public void checklink()
        {
            string actualurl = "http://automationplace.blogspot.com/";
            string expectedurl = "http://automationplace.blogspot.com/";
            Assert.AreEqual(actualurl, expectedurl);
        }
        [Test]
        public void checkurl()
        {

            IWebDriver driver = new ChromeDriver(@"C:\Users\Prashanth_KK\Documents\visual studio 2013\Projects\WebdriverTest\packages\WebDriver.ChromeDriver.26.14.313457.1\tools");
            driver.Navigate().GoToUrl("http://automationplace.blogspot.com/");
            driver.Close();
           

        }
    }
}

 

Open Nunit.exe 


Click on File ->  Open Project 

C:\Users\Prashanth_KK\Documents\Visual Studio 2013\Projects\NunitTest\NunitTest\bin\Debug

Open .exe






 After opening .exe you find the test methods


Click on Run .




That's it.

Hope you like this post.
Hit Like button on Facebook.


1 comment:

  1. I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in Nunit, kindly contact us http://www.maxmunus.com/contact
    MaxMunus Offer World Class Virtual Instructor led training Nunit . We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us:
    Name : Arunkumar U
    Email : arun@maxmunus.com
    Skype id: training_maxmunus
    Contact No.-+91-9738507310
    Company Website –http://www.maxmunus.com



    ReplyDelete