unit testing and tools
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 demoTRANSCRIPT
Unit Testing and Tools
@wbsimms@southshorenet
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
Which would you rather do?
Why Unit Test?
Write TestsFix
Production Bugs
1) Catches regression bugs at the developers desk
2) Documents how code works3) Catalog of the business rules
That’s cute… but really… why?
• Repeatable• Fast• Test by layers• Good Coverage
What makes a good unit test?
Web• Controllers• ViewModels• Helpers
DataAccessLayer• Repositories (or what ever)• Models• Helpers
Other Libraries• Rules Logic• Etc…
Layers?
1. public void MethodName_Case_ExpectedResultTest()
2. [Description(“Your text here”)] public void MethodNameCaseTest()
Test documentation?
All tests all the time! After pull / sync Before commits During CI builds Before you merge After you merge
When to run your test?
• MSTest• Unit testing framework
• Moq• Creating mock objects from interfaces
• Unity• Dependency Injection
• MSBuild• Build automation
• DotCover/Ncover• For coverage analysis
So… the tools?
Deep breath….
Demo time…