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



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,


Published May 23 2008, 09:57 AM by Derik Whittaker
Filed under: ,

Comments

jdn said:

"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.

# May 23, 2008 11:17 AM

Derik Whittaker said:

@jdn,

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

# May 23, 2008 11:21 AM

Casey Charlton said:

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

# May 23, 2008 12:42 PM

Derik Whittaker said:

@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.

# May 23, 2008 1:18 PM

jdn said:

So, you need tests for your tests.

# May 23, 2008 3:07 PM

Derik Whittaker said:

@Jdn,

Now you are getting the idea.

# May 23, 2008 3:14 PM

jdn said:

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

Code breeding like rabbits.  Lower maintainability.

# May 23, 2008 3:30 PM

Michael Wagg said:

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.

# May 24, 2008 6:41 PM

Bill Sorensen said:

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.

# May 27, 2008 1:35 PM

Bill Sorensen said:

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

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

# May 28, 2008 12:45 PM

Peter Mounce said:

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.

# May 29, 2008 7:40 PM

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

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

# May 30, 2008 3:48 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

Red-Gate!