Unit Testing with xUnit.net

Slides:



Advertisements
Similar presentations
XUnit.net Extensibility Brad Wilson Jim Newkirk. Schedule Assert Extensibility9:00 Before/After Extensibility9:45 Fact Extensibility10:15 BREAK10:45 Fixture.
Advertisements

INTRODUCTION CHAPTER #1 Visual Basic.NET. VB.Net General features It is an object oriented language  In the past VB had objects but focus was not placed.
The 2007 Microsoft Office System Servers Enterprise Content Management, Workflow and Forms Martin Parry Developer and Platform Group, Microsoft Ltd
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
10/18/2017 3:02 AM © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN.
What is it all about? .NET MeetUp in Prague, CZ (2017/7/19)
Joy Rathnayake Senior Architect – Virtusa Pvt. Ltd.
12/29/2017 2:33 PM © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN.
C# and VB code-focused development with Visual Studio
Unleash .NET 2015 in your apps
Introduction to ASP.NET Core
5/9/2018 9:30 AM BRK2215 Deliver better experiences with SharePoint Patterns and Practices Community Solutions Mike Ammerlaan Product Marketing Manager,
TESTING TEST DRIVEN DEVELOPMENT
5/15/2018 © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks.
5/15/2018 5:43 PM © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN.
DotnetConf 9/10/2018 7:49 PM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE.
Unit testing your metro style apps built using XAML
The Modern ASP.NET Tech Stack!
Building a Continuous Delivery Pipeline for ASP.NET Core Apps
Introduction to .NET Framework Ch2 – Deitel’s Book
Getting Started with Visual Studio Tools for Tizen
ASP.NET in Linux and Windows containers
Modern Web Development
Modern Front-End Web Development with Visual Studio
Introducing ASP.NET Core 2.0
Microsoft Virtual Academy
Build /21/2018 © 2015 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION.
.NET Standard Jon Galloway | Executive Director, .NET |
Module 1: Getting Started
Microsoft Build /8/2018 5:15 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY,
What is it all about? .NET MeetUp in Amsterdam, NL (2017/7/11)
Microsoft Ignite NZ October 2016 SKYCITY, Auckland
Introduction to Windows Azure Web Sites
Microsoft Build /14/ :29 PM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY,
Microsoft Build /15/2018 6:28 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY,
Microsoft Virtual Academy
.NET and .NET Core Foot View of .NET Pan Wuming 2017.
Learn. Imagine. Build. .NET Conf
Microsoft Build /24/2018 4:02 PM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY,
Unit Testing with xUnit.net-Part-2
Office 365 Development.
Entity Framework Core.
Microsoft Build /30/2018 2:15 AM Migrating Silverlight Windows Phone apps to the Universal Windows Platform Ricardo Villalobos Principal SDE Manager.
Microsoft Connect /1/2018 2:36 AM
Application Insights Diagnostics Preview
MIX 09 12/8/2018 4:33 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Jim Nakashima Program Manager Cloud Tools
Windows Template Studio
1/14/2019 3:57 AM © 2004 Microsoft Corporation. All rights reserved.
Microsoft Connect /17/2019 9:55 PM
Microsoft Connect /16/ :45 PM
Microsoft Ignite /17/2019 6:00 PM
TechEd /22/2019 9:22 PM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Office 365 Development.
Microsoft Connect /24/ :10 PM
From Development to Production: Optimizing for Continuous Delivery
Microsoft Build /27/2019 2:26 PM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY,
SharePoint Development
Microsoft Office 4/3/2019 Deep Dive into native Universal App development with the Office 365 APIs Speaker name Title Microsoft Corporation © 2012 Microsoft.
From Development to Production: Optimizing for Continuous Delivery
4/12/2019 5:27 PM © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN.
Learning with Xamarin Workbooks
Build /19/2019 © 2015 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION.
What’s new in Visual Studio 2012
5/6/2019 7:40 PM © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS.
7/19/2019 2:53 AM © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered.
Blazor A new framework for browser-based .NET apps Ryan Nowak
11/11/2019 1:15 PM © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN.
DataBase Application .NET
Microsoft Connect /14/ :11 AM
Presentation transcript:

Unit Testing with xUnit.net Microsoft Connect 2016 6/1/2018 2:09 PM Unit Testing with xUnit.net Kishorekumar © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Agenda What is Xunit.net Why xUnit.net Installation Running Test Microsoft Connect 2016 6/1/2018 2:09 PM Agenda What is Xunit.net Why xUnit.net Installation Running Test Asserts Data Driven Tests Comparing xUnit.net with other Frameworks © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

6/1/2018 2:09 PM What is xunit.net xUnit.net is a free, open source, community- focused unit testing tool for the .NET Framework. Written by the original inventor of NUnit v2, xUnit.net is the latest technology for unit testing C#, F#, VB.NET and other .NET languages. xUnit.net works with ReSharper, CodeRush, TestDriven.NET and Xamarin. It is part of the .NET Foundation, and operates under their code of conduct. It is licensed under Apache 2 (an OSI approved license). Created in 2007 by 2 ex-Microsofteees James Newkirk @jamesnewkirk Brad Wilson @bradwilson Quick links http://xunit.github.io Official web site https://github.com/xunit 1095 commits, 1336 stars, 57 contributors, 379 forks https://twitter.com/xunit 2282 followers https://www.nuget.org/packages/xunit More than 5M downloads © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Design Goals and Features Microsoft Connect 2016 6/1/2018 2:09 PM Design Goals and Features Multiple Platforms Parallel Test Execution Data Driven Tests Extensible Nuget Packaging Separate Assertions © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Supported Platforms Desktop Class Libraries Portable Class Libraries Universal Apps (Windows 8.1 & Windows Phone 8.1) Windows 8 Apps Windows Phone 8 Apps Xamarin: MonoAndroid, MonoTouch(iOS Classic), iOS Unified Apps ASP.NET 5: Windows, Linux, OS X (xUnit2.1) http://xunit.github.io/#runners

Why xUnit.net?

Lessons learned in Unit Testing (2007) Write tests using the 3A pattern (Arrange, Act, Assert) Keep Your Tests Close (to production code) Use Alternatives to ExpectedException (leads to uncertainty, violates AAA) Use Small Fixtures (smaller & more focused test classes) Don’t use SetUp/TearDown, TestInit/TestCleanup, … (improve readability & isolation) Don’t use abstract base test classes (improve readability & isolation) Improve testability with Inversion of Control (Better test isolation & decoupled class implementation

xUnit Features Flexibility: static and private methods Reduce Friction: fewer attributes Safety: create a new instance for every test Be explicit: no control flow in attributes Runners: be everywhere the developer is Consistency: Prefer the language & framework Extensibility: not an afterthought TDD first: built with and for TDD

Getting Started http://xunit.github.io/docs/getting-started.html Installation Getting Started http://xunit.github.io/docs/getting-started.html Create a class library A test project is just a class library Add a reference to xUnit.net Write your first tests Add a reference to a xUnit.net runner Console or VS

Running Tests Via Visual Studio Test Explorer Install-Package xunit.runner.visualstudio Via the console test runner Install-Package xunit.runner.console

Test Discovery and Essential Attributes Facts are tests which are always true. They test invariant conditions. Theories are tests which are only true for a particular set of data (Data Driven Tests)

Asserts Assert: “to state (something) in a strong and definite way” -http://www.merriam-webster.com Confirm the thing we’re testing behaved as expected Assert.Equal(expected result, actual result); How many asserts per test? Single assert per test Multiple asserts per test Assert.Equal Assert.Null Assert.Throws

Asserting Test Results Numeric Values Assert.Equals Integer values Floating point double values String Values Simple string equality Case sensitivity String contents, starting, ending Asserting using regular expressions

Asserting Test Results Null and Boolean Values True/False Results Null Collections Assert all items in a collection Collection contain specific item Collection doesn’t contain an item Contains an item satisfying a predicate Collection has all expected items

Asserting Test Results Microsoft Connect 2016 6/1/2018 2:09 PM Asserting Test Results Exceptions Asserting that exceptions are thrown Asserting exception details Object Types Asserting exact object types Asserting derived types © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Data Driven Tests A single test method that can be executed multiple times, each time using a discreet set of test data, with each execution representing an individual case. Benefits Reduced test Code Duplication Reduced Maintenance Cost Add New test cases More Quickly External test data Sources

Theory Data Types InlineData MemberData ClassData ExcelData

Questions ?