about approvaltests for better unit testing

27
An open source library for better Unit Testing Woody Zuill & Lynn Langit Agile 2012 – August 2012

Upload: lynn-langit

Post on 11-May-2015

3.645 views

Category:

Technology


3 download

DESCRIPTION

Deck for talk at SoCalCodeCamp on ApprovalTests for Unit Testing

TRANSCRIPT

Page 1: About ApprovalTests for Better Unit Testing

An open source library for better Unit Testing

Woody Zuill & Lynn Langit

Agile 2012 – August 2012

Page 2: About ApprovalTests for Better Unit Testing

Building your Testing ToolkitTest Runner

Nunit, MSTest, JUnit, XUnitCode

Asserts, otherLibraries

Approval TestsManual testsAutomated tests & tools

Differencing Tools

Page 3: About ApprovalTests for Better Unit Testing

Approval Tests and Test Types

Page 4: About ApprovalTests for Better Unit Testing

Using Unit Tests

• New Code - application code (components)• Testing APIs – functionality, edge cases• Legacy Code – locking tests• Learning new APIs – scope, functionality

Page 5: About ApprovalTests for Better Unit Testing

Unit Testing Output?

• Granularity• Feedback• Specification• Regression

Page 6: About ApprovalTests for Better Unit Testing

Why use ApprovalTests?

• Simple = easy to test = use Asserts– Ex. Verify a Scalar Value

• Complex = hard to test = use ApprovalTests– Ex. Verify Array Values– Ex. Verify a GUI– Ex. Verify a Database

query

Page 7: About ApprovalTests for Better Unit Testing

DEMOGetting started

Page 8: About ApprovalTests for Better Unit Testing

How Test-Driven

TDD• Assert• Do• Verify

BDD• Think Bigger• Less Code• Scenarios

ApprovalTests fit in with both types of testing

Page 9: About ApprovalTests for Better Unit Testing

DEMOTesting Arrays

Page 10: About ApprovalTests for Better Unit Testing

Testing Circle

Page 11: About ApprovalTests for Better Unit Testing

About Reporters

• Reporters are DiffTools• ApprovalTests includes

support for many Reporters

• It’s simple to add hooks to your favorite diff tool

Page 12: About ApprovalTests for Better Unit Testing

How to Approve

Contents provided are serialized to the file as binary (for comparison)• Rename *.received to *.approved• Right click ‘Approve’ (VS plug-in)• Right click ‘Use whole file’ (DiffReporter)• Copy ‘Move’ statement

from Test Results to command window

Page 13: About ApprovalTests for Better Unit Testing

DEMOApproving GUIs

• HTML• Browser/text diff• ASP.NET• ASP.NET verify

Page 14: About ApprovalTests for Better Unit Testing

Code must be Testable• Easy to write tests for it• Runnable tests must

exist– Write one test that

passes– Then write another test

on another method– Return to the first test

when needed

Page 15: About ApprovalTests for Better Unit Testing

Peel and Slice Videos

• 3 videos in .NET (Mocks) series ‘peel, slice and peel and slice’

• Getting ready to use (data) Loaders

Page 16: About ApprovalTests for Better Unit Testing

Testing Data Loading

• Mocks (fakes) data population• Tests the USE of data • Does not require a live connection to the

database• Thin layer (ILoader) which decouples data load• Unit Tests test without dependencies

Page 17: About ApprovalTests for Better Unit Testing

Data Usage Patterns

Load

Save

Manipulate

Common Preferred

Page 18: About ApprovalTests for Better Unit Testing

DEMOTesting calls to a Database

llangit
must explain loaders
Page 19: About ApprovalTests for Better Unit Testing

Integration Testing• Allows testing of functionality across multiple

objects (behavior or scenarios)• Example testing ASP.NET MVC – video here

Page 20: About ApprovalTests for Better Unit Testing

Legacy Code

How much of your code base is dead code?

Page 21: About ApprovalTests for Better Unit Testing

Locking Tests (Characterization Tests)

• Test to enable refactoring• Ensures system still works

the same• Most often used with

Legacy Code• Quickly results in high test

coverage

Page 22: About ApprovalTests for Better Unit Testing

DEMOLegacy Code – Chart Smart

Page 23: About ApprovalTests for Better Unit Testing

Visual Studio Code Coverage Config

Page 24: About ApprovalTests for Better Unit Testing

Code CoverageHow much of your code base is covered?

Page 25: About ApprovalTests for Better Unit Testing

Who wrote ApprovalTests?

Dan Gilkerson

LlewellynFalco

Page 26: About ApprovalTests for Better Unit Testing

For More Information• www.ApprovalTests.com• Pick your language &

download• Pick your diff tool• Reference, Approve & Enjoy• Learn more – videos (.NET)• Podcast - HerdingCode

Page 27: About ApprovalTests for Better Unit Testing

APPROVAL TESTSQ & A

@LynnLangit@WoodyZuill