SlideShare a Scribd company logo
MAXIME LEMAITRE – 10/09/2015
xUnit.net
… Assert.Awesome(‘‘xUnit.net’’)…
Agenda
• Business Card
• Why xUnit.net ?
• Compatibility & Comparisons
• Concepts
• Extensibility
• Demo
• Conclusion
• Question
xUnit.net Business Card
• 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
850 commits, 800 stars, 35 contributors, 250 forks
– https://twitter.com/xunit
1400 followers
– https://www.nuget.org/packages/xunit
More than 1M downloads (just for the main pkg)
(2007) – “Since the release of NUnit 2.0,
there have been millions of lines of code
written using the various unit testing
frameworks for .NET. About a year ago it
became clear to myself –James- and Brad
that there were some very clear patterns
of success (and failure) with the tools we
were using for writing tests. Rather than
repeating guidance about “do X” or “don’t
do Y”, it seemed like it was the right time to
reconsider the framework itself and see if
we could codify some of those rules.”,
James Newkirk
Lessons learned in Unit Testing (2007)
1. Write tests using the 3A pattern (Arrange, Act, Assert)
2. Keep Your Tests Close (to production code)
3. Use Alternatives to ExpectedException (leads to
uncertainty, violates AAA)
4. Use Small Fixtures (smaller & more focused test classes)
5. Don’t use SetUp/TearDown, TestInit/TestCleanup, …
(improve readability & isolation)
6. Don’t use abstract base test classes (improve readability
& isolation)
7. Improve testability with Inversion of Control (Better test
isolation & decoupled class implementation
Why Build xUnit.net ?
http://bradwilson.typepad.com/presentations/xunit-v2.pdf
• 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
Test Runner Compatibility
Comparing xUnit.net to other frameworks
Unit 2.2 MSTest 2005 xUnit.net 2.x Comments
[Test] [TestMethod] [Fact] Marks a test method.
[TestFixture] [TestClass] n/a
xUnit.net does not require an attribute for a test class; it
looks for all test methods in all public lasses in the assembly.
[ExpectedException]
[ExpectedExce
ption]
Assert.Throws
Record.Exception
xUnit.net has done away with the ExpectedException
[SetUp] [TestInitialize] Constructor
We believe that use of [SetUp] is generally bad. However,
you can implement a parameterless constructor as a direct
replacement.
[TearDown] [TestCleanup] IDisposable.Dispose
We believe that use of [TearDown] is generally bad, but you
can implementIDisposable.Dispose as a direct replacement.
[TestFixtureSetUp] [ClassInitialize] IClassFixture<T> To get per-class fixture setup, use IClassFixture<T>
[TestFixtureTearDown] [ClassCleanup] IClassFixture<T> To get per-class fixture teardown, use IClassFixture<T>
n/a n/a ICollectionFixture<T>
To get per-collection fixture setup and teardown,
implement ICollectionFixture<T> on your test collection.
[Ignore] [Ignore] [Fact(Skip="reason")] Set the Skip parameter on the [Fact] attribute.
[Property] [TestProperty] [Trait] Set arbitrary metadata on a test
n/a [DataSource]
[Theory]
[XxxData]
Theory (data-driven test).
Comparing xUnit.net to other frameworks
NUnit 2.2 MSTest 2005 xUnit.net 1.x Comments
AreEqual
AreNotEqual
AreEqual
AreNotEqual
Equal
NotEqual
MSTest and xUnit.net support generic versions of
this method
AreNotSame
AreSame
AreNotSame
AreSame
NotSame
Same
n/a n/a DoesNotThrow
Ensures that the code does not throw any
exceptions
Greater / Less n/a n/a
xUnit.net alternative: Assert.True(x > y)
Assert.True(x < y)
Ignore Inconclusive n/a
IsEmpty
IsNotEmpty
n/a
Empty
NotEmpty
IsFalse
IsTrue
IsFalse
IsTrue
False
True
IsInstanceOfType
IsNotInstanceOfType
IsInstanceOfType
IsNotInstanceOfType
IsType
IsNotType
IsNotNull
IsNull
IsNotNull
IsNull
NotNull
Null
n/a n/a NotInRange Ensures that a value is not in a given inclusive range
n/a n/a Throws Ensures that the code throws an exact exception
Concepts
Two different major types of unit tests
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)
More data sources for theories
PropertyData ClassData
11
Shared Context between Tests
http://xunit.github.io/docs/shared-context.html
Constructor and Dispose
shared setup/cleanup code
without sharing object instances
Class Fixtures
shared object instance across
tests in a single class
Collection Fixtures
shared object instances across
multiple test classes
Extensibility
xUnit Extensibility
Half a decade of developer requests
• Assert (Sample: AssertExtensions )
Use 3rd party assertions or create custom
• Before/After (Sample : UseCulture)
Run code before & after each test runs
• Class Fixtures (Sample : ClassFixtureExample)
Run code before & after all tests in test class
• Collection Fixtures (Sample: CollectionFixtureExample )
Run code before & after all tests in test collection
• Theory Data (Sample: ExcelDataExample )
Provide new DataAttribute
• Test Ordering (Sample: TestOrderExamples)
• Traits (Sample: TraitExtensibility)
• FactAttribute (Sample: TheoryAttribute)
What does it mean to be a test?
• Test frameworks
What does it mean to find and run tests?
• Runners
And the Test result is GREEN.
The AutoDataAttribute simply uses a Fixture
object to create the objects declared in the
unit tests parameter list (primitives and
complex types like Mock<T>)…
15
Mixing all together …
xUnit+Moq+AutoFixture
What is the result
of this test ?
Demo
Getting Started
http://xunit.github.io/docs/getting-started.html
1. Create a class library
A test project is just a class library
2. Add a reference to xUnit.net
3. Write your first tests
4. 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
Via any test runner …
• Nuget ‘All the way’
No vsix to install, no templates to install, no setups, … simply nuget as we love it
• Great Community & Active Development
xUnit.net is free and open source. The code is hosted on github (850 commits, 3R
contibutors, 800 stars, 250 forks) and the official twitter account has 1400
followers. Many extensions are available (Moq, AutoFixture, …)
• Part of the Next ‘Big Thing’
Do you know ASP.NET 5, Xamarin, DNX, …? xUnit will be the first class citizen and
default choice in .NET in the future
• Well Integrated in the .NET Ecosystem
No troubles to use it because it is already supported everywhere : Team
Foundation Server, CruiseControl.net, AppVeyor, TeamCity, Resharper …
• It Helps to Write “Better, Faster, Stronger” Tests
This is the essence of xUnit.net. codify patterns of success (and failure)
19
Why moving to xUnit ?
Questions
References
• http://xunit.github.io/
• http://jamesnewkirk.typepad.com/LessonsLearnedinProgrammerTesting.pdf
• http://bradwilson.typepad.com/presentations/xunit-v2.pdf
• http://www.codeproject.com/Articles/825248/The-Dynamic-Duo-of-Unit-Testing-xUnit-net-and-Auto
• https://github.com/xunit/samples.xunit
• http://blog.ploeh.dk/2010/10/08/AutoDataTheorieswithAutoFixture/
About Us
• Betclic Everest Group, one of the world leaders in online
gaming, has a unique portfolio comprising various
complementary international brands: Betclic, Everest
Poker/Casino, Bet-at-home, Expekt, Imperial Casino, Monte-
Carlo Casino…
• Through our brands, Betclic Everest Group places expertise,
technological know-how and security at the heart of our
strategy to deliver an on-line gaming offer attuned to the
passion of our players. We want our brands to be easy to use
for every gamer around the world. We’re building our
company to make that happen.
• Active in 100 countries with more than 12 million customers
worldwide, the Group is committed to promoting secure and
responsible gaming and is a member of several international
professional associations including the EGBA (European
Gaming and Betting Association) and the ESSA (European
Sports Security Association).
We want our Sports betting, Poker, Horse racing and
Casino & Games brands to be easy to use for every
gamer around the world. Code with us to make that
happen.
Look at all the challenges we offer HERE
Check our Employer Page
Follow us on LinkedIn
WE’RE HIRING !

More Related Content

PDF
Visual Studio Profiler
Betclic Everest Group Tech Team
 
PPTX
Unit Testing with xUnit.net - Part 2
BizTalk360
 
PDF
Mini-Training: NFluent
Betclic Everest Group Tech Team
 
PPTX
Junit, mockito, etc
Yaron Karni
 
PPTX
I gotta dependency on dependency injection
mhenroid
 
PPT
Singleton design pattern
11prasoon
 
PDF
Breaking Dependencies to Allow Unit Testing
Steven Smith
 
PPT
Introduction to Design Patterns and Singleton
Jonathan Simon
 
Visual Studio Profiler
Betclic Everest Group Tech Team
 
Unit Testing with xUnit.net - Part 2
BizTalk360
 
Mini-Training: NFluent
Betclic Everest Group Tech Team
 
Junit, mockito, etc
Yaron Karni
 
I gotta dependency on dependency injection
mhenroid
 
Singleton design pattern
11prasoon
 
Breaking Dependencies to Allow Unit Testing
Steven Smith
 
Introduction to Design Patterns and Singleton
Jonathan Simon
 

What's hot (20)

PPTX
Singleton Design Pattern - Creation Pattern
Seerat Malik
 
PPTX
Reactive Extensions
RTigger
 
PPTX
Singleton Pattern
Reber Novanta
 
PPT
Unit testing framework
Igor Vavrish
 
PPTX
Observer & singleton pattern
babak danyal
 
PDF
Property based testing - Less is more
Ho Tien VU
 
PPTX
Application of the Actor Model to Large Scale NDE Data Analysis
ChrisCoughlin9
 
PPTX
Javasession6
Rajeev Kumar
 
PDF
Unit Tesing in iOS
Ciklum Ukraine
 
PDF
Java - Singleton Pattern
Charles Casadei
 
PPTX
Csise15 codehunt
Tao Xie
 
PPTX
Transferring Software Testing and Analytics Tools to Practice
Tao Xie
 
PPTX
Easy mock
Srikrishna k
 
PDF
Learning on Deep Learning
Shelley Lambert
 
PDF
Advanced Java Testing @ POSS 2019
Vincent Massol
 
PPT
Iterator Design Pattern
Varun Arora
 
PDF
Building XWiki
Vincent Massol
 
PDF
Effective Unit Testing
Narendra Pathai
 
PDF
Writing testable code
Thiago Figueredo Cardoso
 
PDF
New types of tests for Java projects
Vincent Massol
 
Singleton Design Pattern - Creation Pattern
Seerat Malik
 
Reactive Extensions
RTigger
 
Singleton Pattern
Reber Novanta
 
Unit testing framework
Igor Vavrish
 
Observer & singleton pattern
babak danyal
 
Property based testing - Less is more
Ho Tien VU
 
Application of the Actor Model to Large Scale NDE Data Analysis
ChrisCoughlin9
 
Javasession6
Rajeev Kumar
 
Unit Tesing in iOS
Ciklum Ukraine
 
Java - Singleton Pattern
Charles Casadei
 
Csise15 codehunt
Tao Xie
 
Transferring Software Testing and Analytics Tools to Practice
Tao Xie
 
Easy mock
Srikrishna k
 
Learning on Deep Learning
Shelley Lambert
 
Advanced Java Testing @ POSS 2019
Vincent Massol
 
Iterator Design Pattern
Varun Arora
 
Building XWiki
Vincent Massol
 
Effective Unit Testing
Narendra Pathai
 
Writing testable code
Thiago Figueredo Cardoso
 
New types of tests for Java projects
Vincent Massol
 
Ad

Similar to Mini training - Moving to xUnit.net (20)

PPTX
Unit Testing in .NET Core 7.0 with XUnit.pptx
Knoldus Inc.
 
DOCX
Test Driven Development
Anand Kumar Rajana
 
PPTX
Unit tests and TDD
Roman Okolovich
 
PDF
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
flufftailshop
 
PDF
New types of tests for Java projects
Vincent Massol
 
PDF
Test Driven Development with Sql Server
David P. Moore
 
PPTX
PREDICT THE FUTURE , MACHINE LEARNING & BIG DATA
DotNetCampus
 
PPTX
Net campus2015 antimomusone
DotNetCampus
 
PPTX
Test-Driven Design Insights@DevoxxBE 2023.pptx
Victor Rentea
 
ODP
Beginners - Get Started With Unit Testing in .NET
Baskar K
 
PPTX
VT.NET 20160411: An Intro to Test Driven Development (TDD)
Rob Hale
 
PDF
Gallio Crafting A Toolchain
ConSanFrancisco123
 
PPTX
Testing Ext JS and Sencha Touch
Mats Bryntse
 
PPTX
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Codecamp Romania
 
PPTX
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
ICS
 
PPT
xUnit Style Database Testing
Chris Oldwood
 
PDF
Testing Django Applications
Gareth Rushgrove
 
PPTX
Test driven development in .Net - 2010 + Eclipse
UTC Fire & Security
 
PPT
Design Patterns
Rafael Coutinho
 
PDF
Feature Bits at LSSC10
Erik Sowa
 
Unit Testing in .NET Core 7.0 with XUnit.pptx
Knoldus Inc.
 
Test Driven Development
Anand Kumar Rajana
 
Unit tests and TDD
Roman Okolovich
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
flufftailshop
 
New types of tests for Java projects
Vincent Massol
 
Test Driven Development with Sql Server
David P. Moore
 
PREDICT THE FUTURE , MACHINE LEARNING & BIG DATA
DotNetCampus
 
Net campus2015 antimomusone
DotNetCampus
 
Test-Driven Design Insights@DevoxxBE 2023.pptx
Victor Rentea
 
Beginners - Get Started With Unit Testing in .NET
Baskar K
 
VT.NET 20160411: An Intro to Test Driven Development (TDD)
Rob Hale
 
Gallio Crafting A Toolchain
ConSanFrancisco123
 
Testing Ext JS and Sencha Touch
Mats Bryntse
 
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Codecamp Romania
 
[Webinar] Qt Test-Driven Development Using Google Test and Google Mock
ICS
 
xUnit Style Database Testing
Chris Oldwood
 
Testing Django Applications
Gareth Rushgrove
 
Test driven development in .Net - 2010 + Eclipse
UTC Fire & Security
 
Design Patterns
Rafael Coutinho
 
Feature Bits at LSSC10
Erik Sowa
 
Ad

More from Betclic Everest Group Tech Team (20)

PPTX
Mini training - Reactive Extensions (Rx)
Betclic Everest Group Tech Team
 
PPTX
Mini training - Introduction to Microsoft Azure Storage
Betclic Everest Group Tech Team
 
PPTX
Mini training- Scenario Driven Design
Betclic Everest Group Tech Team
 
PDF
Email Management in Outlook
Betclic Everest Group Tech Team
 
PDF
Mini-Training: SSO with Windows Identity Foundation
Betclic Everest Group Tech Team
 
PPTX
Training - What is Performance ?
Betclic Everest Group Tech Team
 
PPTX
Mini-Training: Docker
Betclic Everest Group Tech Team
 
PDF
Mini Training Flyway
Betclic Everest Group Tech Team
 
PDF
Mini-Training: NDepend
Betclic Everest Group Tech Team
 
PDF
Management 3.0 Workout
Betclic Everest Group Tech Team
 
PDF
Lean for Business
Betclic Everest Group Tech Team
 
PPTX
Short-Training asp.net vNext
Betclic Everest Group Tech Team
 
PPTX
Training – Going Async
Betclic Everest Group Tech Team
 
PDF
Mini-Training: Mobile UX Trends
Betclic Everest Group Tech Team
 
PPTX
Training: MVVM Pattern
Betclic Everest Group Tech Team
 
PPTX
Mini-training: Personalization & Recommendation Demystified
Betclic Everest Group Tech Team
 
PPTX
Mini-training: Let’s Git It!
Betclic Everest Group Tech Team
 
PDF
AngularJS Best Practices
Betclic Everest Group Tech Team
 
PDF
Mini-Training: Roslyn
Betclic Everest Group Tech Team
 
Mini training - Reactive Extensions (Rx)
Betclic Everest Group Tech Team
 
Mini training - Introduction to Microsoft Azure Storage
Betclic Everest Group Tech Team
 
Mini training- Scenario Driven Design
Betclic Everest Group Tech Team
 
Email Management in Outlook
Betclic Everest Group Tech Team
 
Mini-Training: SSO with Windows Identity Foundation
Betclic Everest Group Tech Team
 
Training - What is Performance ?
Betclic Everest Group Tech Team
 
Mini-Training: Docker
Betclic Everest Group Tech Team
 
Mini Training Flyway
Betclic Everest Group Tech Team
 
Mini-Training: NDepend
Betclic Everest Group Tech Team
 
Management 3.0 Workout
Betclic Everest Group Tech Team
 
Short-Training asp.net vNext
Betclic Everest Group Tech Team
 
Training – Going Async
Betclic Everest Group Tech Team
 
Mini-Training: Mobile UX Trends
Betclic Everest Group Tech Team
 
Training: MVVM Pattern
Betclic Everest Group Tech Team
 
Mini-training: Personalization & Recommendation Demystified
Betclic Everest Group Tech Team
 
Mini-training: Let’s Git It!
Betclic Everest Group Tech Team
 
AngularJS Best Practices
Betclic Everest Group Tech Team
 
Mini-Training: Roslyn
Betclic Everest Group Tech Team
 

Recently uploaded (20)

PDF
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
PDF
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 
PDF
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
PPTX
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
PDF
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
PDF
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
PDF
New Download MiniTool Partition Wizard Crack Latest Version 2025
imang66g
 
PPTX
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
PPTX
Presentation about Database and Database Administrator
abhishekchauhan86963
 
PDF
An Experience-Based Look at AI Lead Generation Pricing, Features & B2B Results
Thomas albart
 
PDF
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 
PPTX
Can You Build Dashboards Using Open Source Visualization Tool.pptx
Varsha Nayak
 
PPTX
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
PDF
vAdobe Premiere Pro 2025 (v25.2.3.004) Crack Pre-Activated Latest
imang66g
 
PDF
Immersive experiences: what Pharo users do!
ESUG
 
PDF
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
PDF
Bandai Playdia The Book - David Glotz
BluePanther6
 
PDF
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
PPTX
Explanation about Structures in C language.pptx
Veeral Rathod
 
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
New Download MiniTool Partition Wizard Crack Latest Version 2025
imang66g
 
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
Presentation about Database and Database Administrator
abhishekchauhan86963
 
An Experience-Based Look at AI Lead Generation Pricing, Features & B2B Results
Thomas albart
 
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 
Can You Build Dashboards Using Open Source Visualization Tool.pptx
Varsha Nayak
 
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
vAdobe Premiere Pro 2025 (v25.2.3.004) Crack Pre-Activated Latest
imang66g
 
Immersive experiences: what Pharo users do!
ESUG
 
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
Bandai Playdia The Book - David Glotz
BluePanther6
 
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
Explanation about Structures in C language.pptx
Veeral Rathod
 

Mini training - Moving to xUnit.net

  • 1. MAXIME LEMAITRE – 10/09/2015 xUnit.net … Assert.Awesome(‘‘xUnit.net’’)…
  • 2. Agenda • Business Card • Why xUnit.net ? • Compatibility & Comparisons • Concepts • Extensibility • Demo • Conclusion • Question
  • 3. xUnit.net Business Card • 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 850 commits, 800 stars, 35 contributors, 250 forks – https://twitter.com/xunit 1400 followers – https://www.nuget.org/packages/xunit More than 1M downloads (just for the main pkg) (2007) – “Since the release of NUnit 2.0, there have been millions of lines of code written using the various unit testing frameworks for .NET. About a year ago it became clear to myself –James- and Brad that there were some very clear patterns of success (and failure) with the tools we were using for writing tests. Rather than repeating guidance about “do X” or “don’t do Y”, it seemed like it was the right time to reconsider the framework itself and see if we could codify some of those rules.”, James Newkirk
  • 4. Lessons learned in Unit Testing (2007) 1. Write tests using the 3A pattern (Arrange, Act, Assert) 2. Keep Your Tests Close (to production code) 3. Use Alternatives to ExpectedException (leads to uncertainty, violates AAA) 4. Use Small Fixtures (smaller & more focused test classes) 5. Don’t use SetUp/TearDown, TestInit/TestCleanup, … (improve readability & isolation) 6. Don’t use abstract base test classes (improve readability & isolation) 7. Improve testability with Inversion of Control (Better test isolation & decoupled class implementation
  • 5. Why Build xUnit.net ? http://bradwilson.typepad.com/presentations/xunit-v2.pdf • 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
  • 7. Comparing xUnit.net to other frameworks Unit 2.2 MSTest 2005 xUnit.net 2.x Comments [Test] [TestMethod] [Fact] Marks a test method. [TestFixture] [TestClass] n/a xUnit.net does not require an attribute for a test class; it looks for all test methods in all public lasses in the assembly. [ExpectedException] [ExpectedExce ption] Assert.Throws Record.Exception xUnit.net has done away with the ExpectedException [SetUp] [TestInitialize] Constructor We believe that use of [SetUp] is generally bad. However, you can implement a parameterless constructor as a direct replacement. [TearDown] [TestCleanup] IDisposable.Dispose We believe that use of [TearDown] is generally bad, but you can implementIDisposable.Dispose as a direct replacement. [TestFixtureSetUp] [ClassInitialize] IClassFixture<T> To get per-class fixture setup, use IClassFixture<T> [TestFixtureTearDown] [ClassCleanup] IClassFixture<T> To get per-class fixture teardown, use IClassFixture<T> n/a n/a ICollectionFixture<T> To get per-collection fixture setup and teardown, implement ICollectionFixture<T> on your test collection. [Ignore] [Ignore] [Fact(Skip="reason")] Set the Skip parameter on the [Fact] attribute. [Property] [TestProperty] [Trait] Set arbitrary metadata on a test n/a [DataSource] [Theory] [XxxData] Theory (data-driven test).
  • 8. Comparing xUnit.net to other frameworks NUnit 2.2 MSTest 2005 xUnit.net 1.x Comments AreEqual AreNotEqual AreEqual AreNotEqual Equal NotEqual MSTest and xUnit.net support generic versions of this method AreNotSame AreSame AreNotSame AreSame NotSame Same n/a n/a DoesNotThrow Ensures that the code does not throw any exceptions Greater / Less n/a n/a xUnit.net alternative: Assert.True(x > y) Assert.True(x < y) Ignore Inconclusive n/a IsEmpty IsNotEmpty n/a Empty NotEmpty IsFalse IsTrue IsFalse IsTrue False True IsInstanceOfType IsNotInstanceOfType IsInstanceOfType IsNotInstanceOfType IsType IsNotType IsNotNull IsNull IsNotNull IsNull NotNull Null n/a n/a NotInRange Ensures that a value is not in a given inclusive range n/a n/a Throws Ensures that the code throws an exact exception
  • 10. Two different major types of unit tests 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)
  • 11. More data sources for theories PropertyData ClassData 11
  • 12. Shared Context between Tests http://xunit.github.io/docs/shared-context.html Constructor and Dispose shared setup/cleanup code without sharing object instances Class Fixtures shared object instance across tests in a single class Collection Fixtures shared object instances across multiple test classes
  • 14. xUnit Extensibility Half a decade of developer requests • Assert (Sample: AssertExtensions ) Use 3rd party assertions or create custom • Before/After (Sample : UseCulture) Run code before & after each test runs • Class Fixtures (Sample : ClassFixtureExample) Run code before & after all tests in test class • Collection Fixtures (Sample: CollectionFixtureExample ) Run code before & after all tests in test collection • Theory Data (Sample: ExcelDataExample ) Provide new DataAttribute • Test Ordering (Sample: TestOrderExamples) • Traits (Sample: TraitExtensibility) • FactAttribute (Sample: TheoryAttribute) What does it mean to be a test? • Test frameworks What does it mean to find and run tests? • Runners
  • 15. And the Test result is GREEN. The AutoDataAttribute simply uses a Fixture object to create the objects declared in the unit tests parameter list (primitives and complex types like Mock<T>)… 15 Mixing all together … xUnit+Moq+AutoFixture What is the result of this test ?
  • 16. Demo
  • 17. Getting Started http://xunit.github.io/docs/getting-started.html 1. Create a class library A test project is just a class library 2. Add a reference to xUnit.net 3. Write your first tests 4. Add a reference to a xUnit.net runner Console or VS
  • 18. Running Tests Via Visual Studio Test Explorer Install-Package xunit.runner.visualstudio Via the console test runner Install-Package xunit.runner.console Via any test runner …
  • 19. • Nuget ‘All the way’ No vsix to install, no templates to install, no setups, … simply nuget as we love it • Great Community & Active Development xUnit.net is free and open source. The code is hosted on github (850 commits, 3R contibutors, 800 stars, 250 forks) and the official twitter account has 1400 followers. Many extensions are available (Moq, AutoFixture, …) • Part of the Next ‘Big Thing’ Do you know ASP.NET 5, Xamarin, DNX, …? xUnit will be the first class citizen and default choice in .NET in the future • Well Integrated in the .NET Ecosystem No troubles to use it because it is already supported everywhere : Team Foundation Server, CruiseControl.net, AppVeyor, TeamCity, Resharper … • It Helps to Write “Better, Faster, Stronger” Tests This is the essence of xUnit.net. codify patterns of success (and failure) 19 Why moving to xUnit ?
  • 21. References • http://xunit.github.io/ • http://jamesnewkirk.typepad.com/LessonsLearnedinProgrammerTesting.pdf • http://bradwilson.typepad.com/presentations/xunit-v2.pdf • http://www.codeproject.com/Articles/825248/The-Dynamic-Duo-of-Unit-Testing-xUnit-net-and-Auto • https://github.com/xunit/samples.xunit • http://blog.ploeh.dk/2010/10/08/AutoDataTheorieswithAutoFixture/
  • 22. About Us • Betclic Everest Group, one of the world leaders in online gaming, has a unique portfolio comprising various complementary international brands: Betclic, Everest Poker/Casino, Bet-at-home, Expekt, Imperial Casino, Monte- Carlo Casino… • Through our brands, Betclic Everest Group places expertise, technological know-how and security at the heart of our strategy to deliver an on-line gaming offer attuned to the passion of our players. We want our brands to be easy to use for every gamer around the world. We’re building our company to make that happen. • Active in 100 countries with more than 12 million customers worldwide, the Group is committed to promoting secure and responsible gaming and is a member of several international professional associations including the EGBA (European Gaming and Betting Association) and the ESSA (European Sports Security Association).
  • 23. We want our Sports betting, Poker, Horse racing and Casino & Games brands to be easy to use for every gamer around the world. Code with us to make that happen. Look at all the challenges we offer HERE Check our Employer Page Follow us on LinkedIn WE’RE HIRING !