Skip to main content

Demo Project (NUnit Setup)



Steps--> 
1.Create a new project in console application.

2.Write the production code in a separate class file.I have written a regular calculator that can do addition, substraction, multiplication, division operation.

3.Add a new class library for test purpose.

4.Add a  reference to our production code from our test project.

5.Install NUnit3Test Adapter
Tools->Extensions and Updates->Online->NUnit3 Test Adpter

6.Install NUnit
Reference->Manage Nuget Packages->Online->Nunit

Now we can use NUnit’s attributes and NUnit asserts.

7.Under class library file write the test code using NUnit attributes.


 [TestFixture]

    public class RegularCalcultorTests

    {

        RegularCalculator calculator;

        [SetUp]

        public void BeforeEachTest()

        {

            calculator = new RegularCalculator();

        }

        [Test]

        public void TestAddition()

        {

           var result=calculator.Addition(10, 20);

            Assert.That(result, Is.EqualTo(30));

        }

        [Test]

        public void TestSubtraction()

        {

            calculator = new RegularCalculator();

            var result = calculator.Subtraction(50, 20);

            Assert.That(result, Is.EqualTo(30));

        }

        [Test]

        public void TestMultiplication()

        {

            calculator = new RegularCalculator();

            var result = calculator.Multiplication(10, 20);

            Assert.That(result, Is.EqualTo(200));

        }

        [Test]

        public void TestDivision()

        {

           calculator = new RegularCalculator();

            var result = calculator.Division(40, 20);

            Assert.That(result, Is.EqualTo(2));

        }


        [TearDown]

        public void AfterEachTest()

        {

            calculator = null;

        }

8.After build the code we can see the tests in test explorer and can run from it.


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...

Page Object Model && Page Factory

Page Object Model Design Pattern (POM): Page Object Model is a Design Pattern which has become popular in Selenium Test Automation. It is widely used design pattern in Selenium for enhancing test maintenance and reducing code duplication. In Selenium all we are doing is finding elements and filling values for those elements. For small script it’s easy to maintain . But with time test suite will grow. As we add more and more lines to our code, things become tough.The chief problem with script maintenance is that if 10 different scripts are using the same page element, with any change in that element, we need to change all 10 scripts. This is time consuming and error prone. A better approach to script maintenance is to create a separate class file which would find web elements, fill them or verify them. This class can be reused in all the scripts using that element. In future, if there is a change in the web element, we need to make the change in just 1 class file and not 1...

WebService Testing (SOAPUI Tool)

SOAPUI SoapUI is a tool which can be used for both functional and non-functional testing. SoapUI can be used to test complete RESTful API and SOAP Web Service testing. It supports Functional Testing, Performance Testing, Interoperability Testing, Regression Testing, Load Testing, and much more. SOAPUI tools are used to test webservices but SOAP is an protocol used to sending and receiving messages between web services. Following are some important features of SoapUI. 1. It is capable of performing the role of both client and service. 2. It enables the users to create functional and non-functional tests quickly and in an efficient manner using a single environment. 3. It is purely implemented using JAVA platform. 4. It supports Windows, Mac, multiple Linux dialects. 5.It allows testers to execute automated functional, regression, compliance, and load tests on different Web API. 6.It supports all the standard protocols and technologies to test all kinds of APIs. It is use...