Derik Whittaker

Syndication

News


Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Whitebox vs Blackbox testing (location of unit tests)

Over on the Alt.Net mailing list (here) the topic of where to put your unit tests was the hot topic a few days ago.  This is a topic that I have debated with various people over the past few years.  With all the debates I have had, it is clear to me that there really is no right or wrong way do to this, but it is just a matter of philosophical opinion.

On this list there are various opinions (and supporting experiences to support those opinions) about which method is better or preferred.  As this is a topic that many developers chat about, I thought I would put a list of the various advantages/disadvantages into location.

Whitebox Advantages

  • Location of tests to their corresponding class under test.
  • Very easy to test internal methods without the need of using the InternalVisibleTo attribute.
  • Reduces the number of projects you have in your solution because you will not need a test project for each assembly.

Whitebox Disadvantages

  • Have to add compiler switches to ensure the tests are NOT compiled into the release code.  This is easily done, but is just something else that you have to setup and remember to do.
  • Addition of various test assemblies in the release of your project.  This includes stuff like the test framework assemblies, any mocking assemblies, etc.
  • Slower compilation time.

Blackbox Advantages

  • You test your assembly exactly like a calling application would use the assembly.  This can be very beneficial as it can flush out implementation bugs very easily.
  • If following true TDD, should create a simpler interface as you can only test the calls that are public and this is the way the user will use the assembly.
  • No need to put any special compiler switches in the code in order to not release the tests.
  • No worries about deploying test code as it is in a separate assembly.

Blackbox Disadvantages

  • Additional projects in your solution.
  • May need to add the InternalsVisibleTo to the various assemblies being tested if you need to tests internal methods (if this is the case, you may have a code smell on your hands).

As you can see from the list of pros/cons above, both whitebox and blackbox testing have upsides and downsides.  At the end of the day this comes down to a personal/philosophical decision and both are better then the alternative....NO TESTS.

Till next time,

*** Note, some of the listed advantages/disadvantages above were taken from various postings on the Alt.Net mailing list.  Credit goes to the various authors in these cases ***


Posted 01-28-2008 5:38 AM by Derik Whittaker
Filed under: , , ,

[Advertisement]

Comments

» Daily Bits - January 28, 2008 Alvin Ashcraft’s Daily Geek Bits: Daily links, development, gadgets and raising rugrats. wrote » Daily Bits - January 28, 2008 Alvin Ashcraft’s Daily Geek Bits: Daily links, development, gadgets and raising rugrats.
on 01-28-2008 8:33 AM

Pingback from  » Daily Bits - January 28, 2008 Alvin Ashcraft’s Daily Geek Bits: Daily links, development, gadgets and raising rugrats.

Peter Ritchie wrote re: Whitebox vs Blackbox testing (location of unit tests)
on 01-28-2008 9:20 AM

Those threads just re-inforced (for me) that a variety of testing types should be used.  I.e. both blackbox and whitebox.

Reflective Perspective - Chris Alcock » The Morning Brew #20 wrote Reflective Perspective - Chris Alcock » The Morning Brew #20
on 01-29-2008 3:08 AM

Pingback from  Reflective Perspective - Chris Alcock  » The Morning Brew #20

Advantages & Disadvantage of White Box Testing - Forums wrote Advantages & Disadvantage of White Box Testing - Forums
on 11-17-2008 12:24 AM

Pingback from  Advantages & Disadvantage of White Box Testing - Forums

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)