8 techniques to find problems in your unit tests within 30 seconds

My blog has moved. You can view this post at the following address: http://www.osherove.com/blog/2009/8/31/8-techniques-to-find-problems-in-your-unit-tests-within-30-s.html
Published Monday, August 31, 2009 9:18 AM by RoyOsherove

Comments

Monday, August 31, 2009 10:37 AM by DotNetShoutout

# 8 techniques to find problems in your unit tests within 30 seconds - ISerializable - Roy Osherove's Blog

Thank you for submitting this cool story - Trackback from DotNetShoutout

Monday, August 31, 2009 11:33 AM by Gavin

# re: 8 techniques to find problems in your unit tests within 30 seconds

Roy, Awesome list.  I like the practical examples - If you're doing this, it's wrong because...

The last one was also a big "ohhhh that makes so much sense!"

Monday, August 31, 2009 12:06 PM by Daniel

# re: 8 techniques to find problems in your unit tests within 30 seconds

Do you mean "DateTime.Now" or all "DateTimes"?  If all "DateTimes", can you explain what the alternative would be? It seems like there would be plenty of cases where you need to pass in a DateTime to a method being tested, etc.  

Monday, August 31, 2009 1:22 PM by RoyOsherove

# re: 8 techniques to find problems in your unit tests within 30 seconds

Daniel: I mean DateTime.Now and the like, not any DateTime that is hard coded such as new datetime(2000,1,1).

any dateTime which you have no control of, basically.

(FYI - you can use Isolator to make DateTime.Now return a custom date - just sayin!)

Tuesday, September 01, 2009 7:51 AM by Tormod

# re: 8 techniques to find problems in your unit tests within 30 seconds

Nice list.

Especially liked "DateTime." at the top of the list.

Tuesday, September 01, 2009 11:34 AM by John Meyer

# re: 8 techniques to find problems in your unit tests within 30 seconds

Anytime I write a test involving any kind of formatting (string, number, or date/time), I put the following lines in my test initialization method, to make sure the tests are portable:

Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US");

Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");

Wednesday, September 02, 2009 8:59 AM by andyclap

# re: 8 techniques to find problems in your unit tests within 30 seconds

@John

Most culture problems I've seen stem from the code assuming a culture (usually US). Setting up your tests like this will hide these sort of problems. Ideally you want to test against different cultures.

try the turkish test:

Thread.CurrentThread.CurrentCulture = GetCultureInfo("tr-TR");

Or better still, assign it sequentially from a list of cultures that you're prepared to support. Perhaps even pick one at random each time tests run, so your tests fail at least sometimes, but don't bust-a-gut exhaustively testing every function under every culture.

Saturday, September 05, 2009 7:21 PM by Havadis – 2 | Bulutlararas??

# Havadis – 2 | Bulutlararas??

Pingback from  Havadis – 2 | Bulutlararas??

Sunday, September 06, 2009 2:06 PM by Eric Williams (@motowilliams)

# re: 8 techniques to find problems in your unit tests within 30 seconds

* putting on my fire retardant suit *

Question - how would one go about handling a class that takes in a handful of dependencies in the ctor and the behavior of that class (SUT) depends combinations of

a) if some of the injected dependencies were called (verify)

and/or

b) the results, if any, of those calls to your injected dependencies (multiple mocks)

I ask because I'm wondering if I'm up against a design smell in my current situation.

Monday, September 07, 2009 12:23 AM by Code Monkey Labs

# Weekly Web Nuggets #75

Pick of the week: Scott Hanselman's 2009 Ultimate Developer and Power Users Tool List for Windows General Finding the Needle in the Haystack : Digg’s Sammy Yu talks about how Apache Solr powers the Digg search. (source: Digg blog ) 8 Techniques to Find