Top Banner
http://www.codeplex.com/xunit Jim Newkirk http://jamesnewkirk.typepad.com Brad Wilson http://bradwilson.typepad.com
15

Re-Thinking Unit Testing - Brad Wilson · .NET 1.0 released in January 2002 NUnit 2.0 released in October 2002.NET 2.0 released in November 2005 Years as practitioners, advocates,

Mar 15, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Re-Thinking Unit Testing - Brad Wilson · .NET 1.0 released in January 2002 NUnit 2.0 released in October 2002.NET 2.0 released in November 2005 Years as practitioners, advocates,

http://www.codeplex.com/xunit

Jim Newkirkhttp://jamesnewkirk.typepad.com

Brad Wilsonhttp://bradwilson.typepad.com

Page 2: Re-Thinking Unit Testing - Brad Wilson · .NET 1.0 released in January 2002 NUnit 2.0 released in October 2002.NET 2.0 released in November 2005 Years as practitioners, advocates,

.NET 1.0 released in January 2002NUnit 2.0 released in October 2002

.NET 2.0 released in November 2005Years as practitioners, advocates, and coaches

Millions of real-world unit tests written

Page 3: Re-Thinking Unit Testing - Brad Wilson · .NET 1.0 released in January 2002 NUnit 2.0 released in October 2002.NET 2.0 released in November 2005 Years as practitioners, advocates,

Always prefer the language and frameworkAttributes are metadata, not control flow

Leverage the runners we already useFocus on the core, offer extensibility

Page 4: Re-Thinking Unit Testing - Brad Wilson · .NET 1.0 released in January 2002 NUnit 2.0 released in October 2002.NET 2.0 released in November 2005 Years as practitioners, advocates,

Replaced[Test]with

[Fact] and [Theory]

Page 5: Re-Thinking Unit Testing - Brad Wilson · .NET 1.0 released in January 2002 NUnit 2.0 released in October 2002.NET 2.0 released in November 2005 Years as practitioners, advocates,

Removed [TestFixture]Static test methods

Private test methods

Page 6: Re-Thinking Unit Testing - Brad Wilson · .NET 1.0 released in January 2002 NUnit 2.0 released in October 2002.NET 2.0 released in November 2005 Years as practitioners, advocates,

Create a new instance for each testTests are run in a random order – on purpose!

Page 7: Re-Thinking Unit Testing - Brad Wilson · .NET 1.0 released in January 2002 NUnit 2.0 released in October 2002.NET 2.0 released in November 2005 Years as practitioners, advocates,

Removed [SetUp] and [TearDown]Prefer per-test setup and cleanup

Prefer aspect-like pre- and post-test operationsUse constructor and Dispose as a last resort

Page 8: Re-Thinking Unit Testing - Brad Wilson · .NET 1.0 released in January 2002 NUnit 2.0 released in October 2002.NET 2.0 released in November 2005 Years as practitioners, advocates,

Removed [ExpectedException]

Page 9: Re-Thinking Unit Testing - Brad Wilson · .NET 1.0 released in January 2002 NUnit 2.0 released in October 2002.NET 2.0 released in November 2005 Years as practitioners, advocates,

[Test, ExpectedException(typeof(ArgumentException))]public void WriteTextThrowsForNullText(){

var file = new TempFile(@"C:\Foo\bar.txt");

file.WriteText(null);}

[Fact]public void WriteTextThrowsForNullText(){

var file = new TempFile(@"C:\Foo\bar.txt");

var ex = Record.Exception(() => file.WriteText(null));

Assert.IsType<ArgumentException>(ex);}

Page 10: Re-Thinking Unit Testing - Brad Wilson · .NET 1.0 released in January 2002 NUnit 2.0 released in October 2002.NET 2.0 released in November 2005 Years as practitioners, advocates,

[Test, ExpectedException(typeof(ArgumentException))]public void WriteTextThrowsForNullText(){

var fileSystem = new Mock<IFileSystem>();// Set up stubs and expects, etc.var file = new TempFile(fileSystem.Object);

file.WriteText(null);

fileSystem.Verify();}

Page 11: Re-Thinking Unit Testing - Brad Wilson · .NET 1.0 released in January 2002 NUnit 2.0 released in October 2002.NET 2.0 released in November 2005 Years as practitioners, advocates,

Primary runners: TD.NET, ReSharper, MSBuildSecondary runners: Console, WinForms GUIComing soon: Visual Studio Team Editions

Supports ASP.NET MVC (Preview 3+)

Page 12: Re-Thinking Unit Testing - Brad Wilson · .NET 1.0 released in January 2002 NUnit 2.0 released in October 2002.NET 2.0 released in November 2005 Years as practitioners, advocates,

Override how built-in assertions workAdd pre- and post-test operations

Redefine how to run a test methodRedefine what a test class is

Version independent test runner API

Page 13: Re-Thinking Unit Testing - Brad Wilson · .NET 1.0 released in January 2002 NUnit 2.0 released in October 2002.NET 2.0 released in November 2005 Years as practitioners, advocates,

Built for TDD, with TDDBoot-strapped (xUnit.net tests itself)

Automated acceptance tests

Page 14: Re-Thinking Unit Testing - Brad Wilson · .NET 1.0 released in January 2002 NUnit 2.0 released in October 2002.NET 2.0 released in November 2005 Years as practitioners, advocates,

[RunWithNUnit]

Page 15: Re-Thinking Unit Testing - Brad Wilson · .NET 1.0 released in January 2002 NUnit 2.0 released in October 2002.NET 2.0 released in November 2005 Years as practitioners, advocates,