PDA

View Full Version : Help evaluate technique (newby)


Info
07-16-2003, 02:10 PM
I just finished Part 1 working through the challenge tests at
http://xp123.com/xplor/xp0201/, and I saw myself doing something that I don't
know if is considered good or bad form. I'm posting here hoping for feedback,
postive or negative.

At one point, I had just finished making a test pass, and I didn't see any
refactoring that seemed to be needed. Then I added the next test to my test
class, and saw that it in light of -that- test, there was some refactoring
required before it would be simple to implement.

My decision, at that point was to comment out the new test, so all tests pass
again, then refactor. I refactored in the smallest chunks I could manage, and
ran tests after each change (including sometimes when I expected failures, but
wanted to see if the failures were precisely the ones I expected).

After the refactoring was complete and tests passed, I proceeded to uncomment
the new test again and implement the code to make the test pass. After some
final refactoring, the tests still passed, and I was done with Part 1.

I guess the question would be, at the point where a new test makes some
refactoring seem to be in order, was I right to hold off on the new test, and do
the refactoring first? Or should I have tried to figure out a simple way to get
the next test to pass (though none was coming to mind), then refactor afterward?

Thanks for any feedback,

- Steve Jorgensen

Phlip
07-16-2003, 10:19 PM
Steve Jorgensen wrote:
I just finished Part 1 working through the challenge tests at http://xp123.com/xplor/xp0201/, and I saw myself doing something that I
don't know if is considered good or bad form. I'm posting here hoping for
feedback, postive or negative. At one point, I had just finished making a test pass, and I didn't see any refactoring that seemed to be needed. Then I added the next test to my
test class, and saw that it in light of -that- test, there was some refactoring required before it would be simple to implement. My decision, at that point was to comment out the new test, so all tests
pass again, then refactor. I refactored in the smallest chunks I could manage,
and ran tests after each change (including sometimes when I expected failures,
but wanted to see if the failures were precisely the ones I expected). After the refactoring was complete and tests passed, I proceeded to
uncomment the new test again and implement the code to make the test pass. After
some final refactoring, the tests still passed, and I was done with Part 1. I guess the question would be, at the point where a new test makes some refactoring seem to be in order, was I right to hold off on the new test,
and do the refactoring first? Or should I have tried to figure out a simple way
to get the next test to pass (though none was coming to mind), then refactor
afterward?

You have correctly picked up the meme that all tests are sacred, and none of
them should ever regress.

That meme applies, for Programmer Tests, from the time you commit onwards.

The "suspend a test" pattern applies, quite legitimately, to situations
where growing function X gets easier if function Y would have already
existed first. You comment out test_X and use test_Y to grow Y. Then you go
back and restore test_X and use it to finish X.

There are those who claim to obey the rule "only one interruption level"
here. They won't interrupt test_Y to start test_Z.

And, of course, during a big rework session you'l temporarily disable tests
that "get in the way".

However, if your friendly neighborhood coach catches you...

--
Phlip
http://www.c2.com/cgi/wiki?TestFirstUserInterfaces

Uncle Bob (Robert C. Martin)
07-17-2003, 11:31 AM
Steve Jorgensen <nospam@nospam.nospam> might (or might not) have
written this on (or about) Wed, 16 Jul 2003 22:10:47 GMT, :
I just finished Part 1 working through the challenge tests athttp://xp123.com/xplor/xp0201/, and I saw myself doing something that I don'tknow if is considered good or bad form. I'm posting here hoping for feedback,postive or negative.At one point, I had just finished making a test pass, and I didn't see anyrefactoring that seemed to be needed. Then I added the next test to my testclass, and saw that it in light of -that- test, there was some refactoringrequired before it would be simple to implement.My decision, at that point was to comment out the new test, so all tests passagain, then refactor. I refactored in the smallest chunks I could manage, andran tests after each change (including sometimes when I expected failures, butwanted to see if the failures were precisely the ones I expected).After the refactoring was complete and tests passed, I proceeded to uncommentthe new test again and implement the code to make the test pass. After somefinal refactoring, the tests still passed, and I was done with Part 1.I guess the question would be, at the point where a new test makes somerefactoring seem to be in order, was I right to hold off on the new test, and dothe refactoring first? Or should I have tried to figure out a simple way to getthe next test to pass (though none was coming to mind), then refactor afterward?

I've seen it done both ways, and can't say that either was incorrect.
It's pretty much a judgement call. Most of the time I prefer to
comment out the test and refactor first; but there are times when it's
better to make the second test pass by hook or crook, and then
refactor.


Robert C. Martin | "Uncle Bob"
Object Mentor Inc.| unclebob @ objectmentor . com
PO Box 5757 | Tel: (800) 338-6716
565 Lakeview Pkwy | Fax: (847) 573-1658 | www.objectmentor.com
Suite 135 | | www.XProgramming.com
Vernon Hills, IL, | Training and Mentoring | www.junit.org
60061 | OO, XP, Java, C++, Python |


MyLounge.com Site Map
Forum: Cars, Cell Phone, Database, Games, Home Improvement, IT, Music, School, Sports, Web Design, Web Server, Weight Loss

The MyLounge.com forum is intended for informational use only and should not be relied upon and is not a substitute for any advice. The information contained on MyLounge.com are opinions and suggestions of members and is not a representation of the opinions of MyLounge.com. MyLounge.com does not warrant or vouch for the accuracy, completeness or usefulness of any postings or the qualifications of any person responding. Please consult a expert or seek the services of an attorney in your area for more accuracy on your specific situation. Please note that our forums also serve as mirrors to Usenet newsgroups. Many posts you see on our forums are made by newsgroup users who may not be members of MyLounge.com Term of Service