Devlico.Us
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @devlicious

Derik Whittaker

Thoughts on Software Development, .Net, OOP, Design Patterns and all things cool



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 ***



Comments

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

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

# January 28, 2008 8:33 AM

Peter Ritchie said:

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

# January 28, 2008 9:20 AM

Reflective Perspective - Chris Alcock » The Morning Brew #20 said:

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

# January 29, 2008 3:08 AM

Advantages & Disadvantage of White Box Testing - Forums said:

Pingback from  Advantages & Disadvantage of White Box Testing - Forums

# November 17, 2008 12:24 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Derik Whittaker

Derik is a .Net Developer/Architect specializing in WinForms working out the northern suburbs of Chicago. He is also believer and advocate for Agile development including SCRUM, TDD, CI, etc.

When Derik is not writing code he can be found spending time with his wife and young son, climbing on his bouldering wall, watching sports (mostly baseball), and generally vegging out. Check out Devlicio.us!

Our Sponsors

Proudly Partnered With


This Blog

Syndication

News