How to Write Unit Tests in C#

Slides:



Advertisements
Similar presentations
xUnit Test Patterns (Some) xUnit Test Patterns (in practice) by Adam Czepil.
Advertisements

Module 1: Introduction to SQL Server Reporting Services.
Test Automation: Coded UI Test
Stored procedures and views You can see definitions for stored procedures and views in the demo databases but you can’t change them. For views, expand.
Test-Driven Development José Almeida, Microsoft
Tools for Agile Development: A Developer’s Perspective Mike Linnen Blog:
TEST-DRIVEN DEVELOPMENT Lecture 3. Definition Test-driven development (development through testing) is a technique of programming, in which the unit tests.
Dhananjay Microsoft MVP
Testing by Duncan Butler Sara Stephens. Too much to cover.
JavaScript 101 Lesson 01: Writing Your First JavaScript.
The Internet. Telnet Telnet means using your computer as a terminal. All commands you type are sent to the host computer you are connected to and executed.
#sqlsatPordenone #sqlsat367 February 28, 2015 Testing your databases Alessandro
Database Updates Made Easy In WebFocus Using SQL And HTML Painter Sept 2011 Lender Processing Services 1.
Agenda Unit Test Framework for the XAML app developer Automated end-user testing using Coded UI Test Q&A.
By John Boal  Continuous Integration [CI] ◦ Automating the build process ◦ Build the entire system each time any new.
By for Test Driven Development: Industry practice and teaching tool Robert Vanderwall, Ph.D. 1 WISTPC-15.
Test-Driven Development With Visual Studio 2005 Erno de Weerd Info Support.
TEST-DRIVEN DEVELOPMENT AND MVP Cory Foy and Michael Russo.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
OM. Brad Gall Senior Consultant
Getting Started with the ASP.NET Web API Dhananjay Kumar Infragistics Consultant Microsoft MVP
StyleCop Breaking down the barriers to entry Gary Ewan Park Twitter: Blog:
© Copyright 2005, thycotic. Test Driven Development Jonathan Cogley Maryland Cold Fusion User's Group 10/11/2005.
Clear Lines Consulting · clear-lines.comSilicon Valley Code Camp 2008 · Nov 8, 2008 · 1 Test-Driven Development An introduction for C# developers.
© ALEXANDRE CUVA  VERSION 2.00 Test Driven Design.
By for Testing Tools: Test Automation and supporting tools Jariro Pava, Robert Vanderwall 1 WISTPC-14.
N from what language did C++ originate? n what’s input, output device? n what’s main memory, memory location, memory address? n what’s a program, data?
Getting started with ASP.NET MVC Dhananjay
Service Management Automation: 3,2,1, Automate!
Intro to Datazen.
The Start Menu……..Exposed What you never knew existed.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Visual Studio 2005 Team System: Enabling Better Software Through Testing Tejasvi Kumar Technology Specialist - VSTS Microsoft Corporation
Welcome to Azure App Services! Amie Seisay
Unit Testing. F-22 Raptor Fighter Manufactured by Lockheed Martin & Boeing How many parts does the F-22 have?
JavaScript for C# developers Dhananjay Microsoft MVP
Simplifying the Code First Approach in the Entity Framework Dhananjay Kumar Infragistics Consultant Microsoft MVP
Test Driven Development Introduction Issued date: 8/29/2007 Author: Nguyen Phuc Hai.
How to implement the Repository Pattern in an ASP.NET MVC Application Dhananjay Kumar Developer Evangelist – Infragistics Microsoft MVP
1 The Scholarly Communication Committee blogs are intended to serve as the principal means of written communication among the Scholarly Communication Committee.
Unit Testing in Eclipse Presented by David Eisler 08/09/2014.
Eliminate Team Build Headaches with Unit Tests, WiX and Virtualization Benjamin Day
Martina Grom MVP Office 365 How to (remote) control Office 365 with Azure Toni Pohl MVP Client Dev
Microsoft Customer 2 Partner Connector Quick Reference Guide
Performance Testing Using VSTS Saravana Kumar Microsoft MVP, VSTS Hewlett Packard Saravana Kumar Microsoft MVP, VSTS Hewlett Packard.
Unit testing with NUnit Anne Lam & Chris James CMPS 4113 – Software Engineering April 15, 2015.
UNIT TESTING IN ANGULARJS Dhananjay
Angularjs 2.0 : Getting started
SQL Database Management
Simplifying Objects and Inheritance in JavaScript
Unit Testing - solid fundamentals
Test-driven development
TESTING TEST DRIVEN DEVELOPMENT
Computer Terms Review from what language did C++ originate?
Test Driven Development
Jeff Hollan / Kevin Lam Program Manager / Principal Program Manager- Microsoft Bringing Logic Apps into DevOps with Visual Studio and monitoring.
Solving the Hard Problems
Continuous Integration For Databases
.NET Debugging for the Production Environment
Step by Step - AngularJS
Creating Windows Store Apps Using Visual Basic
Intro to Unit Testing with tSQLt
Jeff Hollan / Kevin Lam Program Manager / Principal Program Manager- Microsoft Bringing Logic Apps into DevOps with Visual Studio and monitoring.
TDD & ATDD 1/15/2019.
What about the Data Dude?
Introduction to VSTS Database Professional
Angular 2 : CRUD Operations
Visual Studio Tools for Unity 2.0 Preview
Introduction to Windbg
Introduction to ASP.NET Parts 1 & 2
Presentation transcript:

How to Write Unit Tests in C# Dhananjay Kumar Infragistics Consultant Microsoft MVP, C# Corner MVP http://debugmode.net

Some Goodies Two active participants among you may win this cool goodies . We will announce winner name in webinar recap blog post which will be published on Infragistics blog Recording of the webinar with all resources will be available on webinar recap blog post We will ask you for your mailing address and courier you the goodies in India

I am Dhananjay Kumar Infragistics Consultant 6 times Microsoft MVP 7 times C-SharpCorner MVP 850+ Blog posts , 70+ talks, and 50 + webinars 7+ years of development and evangelism experience @debug_mode Blog : http://debugmode.net Email : debugmode@outlook.com

Agenda About Unit Test Write Unit Test using MS Test Write Unit Test using NUnit Testing Private Methods Test Set Up and Tear Down Calculator App using TDD

What is Unit Test Unit Test is a piece of code which tests behaviour of a function or class. Unit Tests are written by the developers.

? What is Unit Test Add function Options Input (num1,num2) Sum(num1,num2) ? Options Use function in application and then test it with the application Write code to test the function before it goes to production. This code is called Unit Test

Why Unit Test ? Unit Testing reduces the level of bugs in production code.  Unit Testing saves you development time.  Unit Testing saves time in debugging later Automated Unit tests can be run as frequently as required with different set of input A good Unit Tests are a form of documentation Unit Testing forces you to confront the problem head on Unit Tests allows you to make big changes to code quickly Unit Tests help you really understand the design of the code you are working on. Instead of writing code to do something, you are starting by outlining all the conditions you are subjecting the code to and what outputs you'd expect from that.

Unit Test in .NET Unit Test in .NET MS Test NUnit

Structure of test project SUT project:Calculator class:Calculator method : Add method:Mul Test : Calculator.Tests class:CalculatorTest method: ShouldAddNumbers method:ShouldMulNumbers

AAA Arrange Act Assert

Write Test using MSTest : Demo Add reference of VSTS package in the test project or create a test project by selecting Unit Test project template Add reference of the SUT project Create Test class and Test methods Execute test using Visual Studio Test Explorer

Write Test using Nunit : Demo Add reference of NUnit package in the test project Add reference of the SUT project Create Test class and Test methods Execute test using either of three options. Visual Studio Test Explorer NUnit UI NUnit command prompt

Test SetUp and TearDown Gets executed before execution of first test Test SetUp Gets executed after execution of all the tests. Test Tear Down Create a database connection before execution of first test Create instance of a particular object before execution of first test Delete al connection to data base after execution of all the tests Delete particular file from the system before execution of any test

Test SetUp and TearDown MS Test SetUp : [ClassInitalize] TearDown : [ClassCleanup] NUnit SetUp : [TestFixtureSetUp] TearDown : [TestFixtureTearDown]

Test First Approach or TDD Red Green Refactor Write a failing test (run the test(s) – they should be RED) Make it pass in the simplest way possible (tests are GREEN) Now clean up the code (eliminate duplication and other code smells) (REFACTOR)

Summary What is Unit Test Why Unit Test Write Test using MSTest Write Test using NUnit Test Fixture SetUp and Test Fixture Tear Down Test SetUp and Test TearDown Test First Approach Testing Private methods

What Infragistics can offer you? We welcome all of you to take advantage of a FREE 30 Day Trial by downloading the product at: http://www.infragistics.com/products/ultimate/download Please reach out to us at Sales-India@infragistics.com for any follow up questions you may have. We welcome the opportunity to assist you.