Wednesday, March 21, 2012

Testing Difficult Code

I recently did 3 videos in my ‘Using ApprovalTests in .Net’ series that deal with how to test difficult code. These video actually have very little to do with either .Net or ApprovalTests, but they are common issues you run into when unit testing.


Testing difficult Code comes down to 2 things:

  1. Can I call the Method?
  2. Will the Method run to completion?

And there are 2 techniques I use to deal with these, that individually are useful, but together are amazing.

1. The Peel

The hardest part about long methods is you have to run all of it to test even a small part of it. The idea behind the peel is to break the method up into easy to run pieces.  Here’s the video:

The Peel

2. The Slice (Mocks)

Even if you get into the piece you are looking to test, you might not be able to get all the way through it. That’s where mocks come into place. By slicing off the connection to the actual trouble spot, you can easily fake it, and return to easy to run code.

The Slice

3. The Peel & Slice

So now that you have these Mocks, how do you get them to be used? While there are many forms of dependency injection (inheritance, factory, DI frameworks, IoC) the easiest of all is “Parameter passing”. Of course, to do that you need a nice seam that passes in the default dependency. Sound familiar? This is why the Peel & Slice work so nicely together.

The Peel & The Slice


Ranveer Patil said...

This blog is a great source of information which is very useful for me.
Worldcup 2016 live streaming score watch online
ICC T20 World Cup 2016 Venues expected date

Vicente wiko said...

Rent Catering Info Konten Information Travel Marketing Jual Rumah Informasi Training Jasa Jual Beli Marketing Rumah Jasa Catering jasa training Jasa Akuntansi Little Forum Kursus Online Rental Mobil di Jakarta Lomba SEO Rumah Tangerang Jasa Company Profile

for IT the said...

Great Article
C# Online Training | ASP.NET Training | ASP.NET MVC Training

Dot Net Interview Questions

.net training online | Dot Net Training in Chennai | .Net Training in Chennai | Dot Net Training Institutes in Chennai

Sunny ipank said...

Kursus Online Jasa Jual Beli biro jasa perijinan jasa bangun rumah jual rumah tangerang gading serpong grosi baju korea Jasa Akuntansi jasa kontraktor Promosi Bisnis Online jasa desain furniture Jasa Desain Interior jual apartemen bsd tangerang Jasa Pemasaran Online Konsultan Pajak Jasa Catering Jasa Video Shooting Catering Jakarta Rental Mobil Jakarta Rumah Dijual Alam Sutera biro jasa perijinan jasa bangun rumah jual rumah tangerang gading serpong grosi baju korea Jasa Akuntansi jasa kontraktor Promosi Bisnis Online jasa desain furniture Jasa Desain Interior

Benny carrolina said...

Denah Rumah Tinggal Pagar Balkon Tas Batam Murah Batu Garut Merah Design Interior Minimalis Tas Kw Branded Rumah Murah Di Gadi Model Kanopi Rumah Dijual Di Ala Jual Rumah Bsd Gree Cream Pemutih Muka Toko Wanita Online Harga Gula Pasir 1 Kg Harga Pagar Besi Minimalis Jual Rumah Bsd City Pusat Baju Murah Grosir Murah Cream Pemutih Yang Beton Ringan Kanopi Rumah

Amrish Singh said...

icc t20 world cup
Latest Mobiles in India
Bollywood Hindi Lyrics
IPL t20 live Streaming

Joy Andy said...

ICC World T20 2016 Live Streaming
Holi Wallpaper 2016
Easter 2016 Wishes, Quotes, Images
PEC 5th Class Result 2016
IPL 9 Live Streaming 2016

Burl yuni said...

interior desainer arsitektur modern depan elevations 2 d jasa membuat desain 8 pertanyaan untuk tanya sebelum mempekerjakan self sustaining rotating skyscraper rencana pentingnya desain struktural tipe perencanaan rumah type rumah rencana part 2 model paving block atau conblock pasir sebagai bahan utama material batako bata merah dan bata ringan cara menghitung kebutuhan cor mutu batako beton pengertian drainase atau saluran air cara mempelajari isi box mcb cara membuat taman rumah sederhana pemasangan waterproofing membrane pemasangan paving block klasifikasi block beton terkunci paving block

Rudolf suwiko said...

Grosir Baju Murah Baju Import Murah Baju Branded Grosir Busana Muslim Grosir Baju Dress Shafira Busana Muslim Jual Baju Korea Butik Busana Muslim Jual Baju Online Baju Gamis Murah Grosir Baju Bandung Baju Murah Grosir Distributor Baju Korea Murah Supplier Baju Import Fashion Korea Jual Baju Online Murah Baju Terbaru Grosiran Baju Murah Baju Wanita Murah Baju Murah Grosir