unit testing and tools

10
Unit Testing and Tools @wbsimms @southshorenet

Upload: william-simms

Post on 10-May-2015

527 views

Category:

Technology


1 download

DESCRIPTION

This talk was give at the South Shore .NET Users Group. Unit Testing is now considered a required skill for developers. There are a ton of tools out there. However, there's nothing that shows you how to tie them all together to make your software fast, testable, and flexible. This talk will go over my toolset: • MSTest • Moq - Mocking framework • NCover - for coverage • MSBuild - for automation • Dotcover - coverage from VS • Unity - for dependency injection This talk has a very long demo

TRANSCRIPT

Page 1: Unit Testing and Tools

Unit Testing and Tools

@wbsimms@southshorenet

Page 2: Unit Testing and Tools

Unit test• Code you write to test your code

Coverage• Measure of how much code is tested

Mock• Replacement for something else

Dependency Injection (DI)• Builder design pattern• Object and dependencies are created for you

Continuous Integration (CI)• Responds to checkins, builds code, and generates

code metrics (coverage, unit test pass fail, etc.)

Vocabulary

Page 3: Unit Testing and Tools

Which would you rather do?

Why Unit Test?

Write TestsFix

Production Bugs

Page 4: Unit Testing and Tools

1) Catches regression bugs at the developers desk

2) Documents how code works3) Catalog of the business rules

That’s cute… but really… why?

Page 5: Unit Testing and Tools

• Repeatable• Fast• Test by layers• Good Coverage

What makes a good unit test?

Page 6: Unit Testing and Tools

Web• Controllers• ViewModels• Helpers

DataAccessLayer• Repositories (or what ever)• Models• Helpers

Other Libraries• Rules Logic• Etc…

Layers?

Page 7: Unit Testing and Tools

1. public void MethodName_Case_ExpectedResultTest()

2. [Description(“Your text here”)] public void MethodNameCaseTest()

Test documentation?

Page 8: Unit Testing and Tools

All tests all the time! After pull / sync Before commits During CI builds Before you merge After you merge

When to run your test?

Page 9: Unit Testing and Tools

• MSTest• Unit testing framework

• Moq• Creating mock objects from interfaces

• Unity• Dependency Injection

• MSBuild• Build automation

• DotCover/Ncover• For coverage analysis

So… the tools?

Page 10: Unit Testing and Tools

Deep breath….

Demo time…