The Artima Developer Community
Sponsored Link

Agile Buzz Forum
A Unit Test Pattern

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
A Unit Test Pattern Posted: Nov 22, 2004 6:08 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: A Unit Test Pattern
Feed Title: Travis Griggs - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/travis-rss.xml
Feed Description: This TAG Line is Extra
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Travis Griggs - Blog

Advertisement
There's a pattern that I've begun using with some UnitTests and I kinda like it. Often, I end up with a TestCase that has a single inst var. The setUp method sets that to some default instance of the object being tested. And, if there's an external part (things like files, or windows opened, etc), I use my tearDown to clean it all up. Invariably, I'll end up with one or two tests amongst many that needs TWO instances of the class of interest. Maybe I'm testing comparison, or copying between, or something. So I can wrap the entire test:

[blah
blah
blah] ensure: [make sure you do the equivalent of tearDown for the alternate thing]

That's ugly. And funky to debug. Or, I can add another ivar to setUp and tearDown, which seems, I dunno, bloated.

Lately, I've experimented with having a single collection object that "registers" these things. So end up with methods that look something like:

setUp
	theNormalTestThing := self newThingToTest

tearDown
	self testThings do: [:each | "do the tear down per thing"]

newThingToTest
	self testThings add: (ThingToTest new)

testThings
	^testThings ifNil: [testThings := Set new]
Then for tests that need a second thing to test, they just call the newTestThing, and everything's still cleaned up hunky dorey. There's gotta be a pattern there. I've always wanted to put my name on a pattern.

Read: A Unit Test Pattern

Topic: Rigidity adds Complexity Previous Topic   Next Topic Topic: Deploy First Development

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use