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
Keeping your tests up to date

While putting together one of my last posts one thought kept scrolling through my head.  This was the idea that when you modify your code, you need to make sure your that the intent of your tests still are correct.  I know this concept may seem trivial, but how many of us actually do this.

I think most testing practitioners will agree that simply because a test passes green it does not mean that the test is valid and that the code under test is validly tested.  It would not be to hard to imagine a scenario where your tests still pass after you have made changes to the code/class under test, but because your tests still run green you think you are in the clear.

Now I know you what you are thinking.  You are thinking that if I am changing my code I should be doing so via tests, and you are correct.  But you may be only touching a single test, when multiple tests may be affected.  So we need to just quickly verify all the other tests.

Developers (myself included) need to really get into the habit of verifying affected tests when they change code, regardless of the results of their tests. To be honest, I feel that writing quality tests is harder then writing quality code (more on this here).

Just my thoughts.

Till next time,


Posted 05-23-2008 9:57 AM by Derik Whittaker
Filed under: ,

[Advertisement]

Comments

jdn wrote re: Keeping your tests up to date
on 05-23-2008 11:17 AM

"I think most testing practitioners will agree that simply because a test passes green it does not mean that the test is valid and that the code under test is validly tested"

Perfectly sums up what is wrong with unit testing.  I can double my code and still not have achieved what I was looking for.

Derik Whittaker wrote re: Keeping your tests up to date
on 05-23-2008 11:21 AM

@jdn,

You could also walk though your application for hours/days/weeks and still not achieve what u are looking for :)

Jak Charlton wrote re: Keeping your tests up to date
on 05-23-2008 12:42 PM

If your test still passes it is a valid test, or you made a mistake in your code change  .... you need a new test, not to change an old one ...

Derik Whittaker wrote re: Keeping your tests up to date
on 05-23-2008 1:18 PM

@Casey,

You may be 100% correct.  The intent of the post was really to draw attention to the fact that you need to maintain your tests during code changes.  Do not simply rely on the fact they are Green as an indicator.

jdn wrote re: Keeping your tests up to date
on 05-23-2008 3:07 PM

So, you need tests for your tests.

Derik Whittaker wrote re: Keeping your tests up to date
on 05-23-2008 3:14 PM

@Jdn,

Now you are getting the idea.

jdn wrote re: Keeping your tests up to date
on 05-23-2008 3:30 PM

But then you need tests for your tests for your tests.

Code breeding like rabbits.  Lower maintainability.

Michael Wagg wrote re: Keeping your tests up to date
on 05-24-2008 6:41 PM

I always try and concentrate my tests on stating a specific fact about the code. That way if the test still passes that fact is still true. This is really just about giving your tests realistic names based on the asserts inside them so that you're saying exactly what the test proves rather than what could be implied by those asserts at the time of writing the test.

Doesn't work for everything but this kind of thinking generally keeps me out of trouble.

Bill Sorensen wrote re: Keeping your tests up to date
on 05-27-2008 1:35 PM

I think Behavior Driven Development has it right in that a good test is a specification. If your specifications for the behavior of a class change, then your tests need to change. If the specs are constant and your tests break, you're testing implementation details.

Bill Sorensen wrote re: Keeping your tests up to date
on 05-28-2008 12:45 PM

P.S. Scott Bain says it far better than I can in this podcast:

www.netobjectives.com/.../overcoming-impediments-to-tdd-test-driven-development

Peter Mounce wrote re: Keeping your tests up to date
on 05-29-2008 7:40 PM

It seems like we could be helped out here by a feature on code-coverage analysis or static analysis tools - being able to run a code-query something along the lines of "given this diff, these tests are affected" - to find and review all the tests hit by a code change.

Tip: How to keep unit tests up to date « blog.jemm.net wrote Tip: How to keep unit tests up to date « blog.jemm.net
on 05-30-2008 3:48 AM

Pingback from  Tip: How to keep unit tests up to date « blog.jemm.net

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)