FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
Development Tools
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
September 01, 2004
Swiss Wisdom

Avery's resistance to acceptance tests creates a stumbling block for the DTracker team, as our intrepid Alphonse remains neutral.

Robert C. Martin
Avery's resistance to acceptance tests creates a stumbling block for the DTracker team, as our intrepid Alphonse remains neutral.
Swiss Wisdom

Software Development

Feb. 21, 2002; 1000. In the first decade of the 20th century, Percival Lowell predicted the existence of a ninth planet by studying the motion of Uranus. Though he searched, he died before he could complete the effort. In 1929, Clyde Tombaugh came to Lowell Observatory and resumed Lowell's search for planet X. The procedure was both delicate and tedious. Two photographic plates, taken of the same stretch of sky on different nights, were put into a device known as a "blinker, which displayed the two plates one at a time, quickly alternating between them. Any object on one plate that was in a different position on the other would appear to blink. Clyde Tombaugh found Pluto on Feb. 18, 1930. In the summer of 1935, he found the angel of death.

The newspapers named the rock "Clyde and had a few days poking fun at the notion that Clyde might actually hit the Earth in 1959. But the world was headed for war, and even a possible doomsday rock couldn't hold the papers' attention for long. Besides, as the astronomers kept saying, the odds of a collision were millions to one against ...

Back to the Future

Carole and Jasper grabbed another workstation to work on the next acceptance test while Avery, Jerry and I started working on making the Register Normal Suit test run.

"OK, the first thing we need to do is write the fixture for the first table, Jerry said. "What's a fixture? I asked. "A fixture is a Java class that binds the table to the DTrack application, Jerry replied. "But there is no DTrack application, Avery complained. "True, Jerry answered. "We write the tests and fixtures first to make sure that the application is designed to be testable. "Oh, sort of like writing unit tests first, I replied. "Yes, it's a bit like that, Jerry said, "except we write the whole test and fixture before writing any of the application. In fact, we write many tests and fixtures before writing the application.

"What does a fixture look like? Avery asked.

Jerry pulled up the test that he and Carole had just finished. "Look at the first table.

"Now watch what happens to that table when I hit the Test button.

"Does that mean we have to write a class named DTrackContext? I asked. "Exactly, Jerry replied, passing me the keyboard. "Put it in the dtrack.fixtures package. So I wrote:

"Great, Jerry said. "Now compile that and run the test again. It compiled without a problem, of course; but when I hit the Test button, I got the same error as before. "Do you know why? Jerry asked.

I thought so, but Avery beat me to it by saying, "It's a classpath issue; [FitNesse] doesn't know where the DTrackContext.class file is. "Right, Avery, Jerry beamed. I could see a smug smile flicker across Avery's face. Jerry took the keyboard and made the following changes to the test page:

"This tells FitNesse what the fixture's classpath is, Jerry explained. "But it still fails, Avery complained after hitting the Test button. Jerry looked expectantly at us.

"Oh! I said. "The class's name is dtrack.fixtures.DtrackContext, not just DtrackContext. "Right again! Jerry said as Avery scowled. "Why don't you make that change? So I changed the page to look like this:

And it displayed like this:

"I can sort of see the syntax of this, I said. "The strokes are table cell separators, but what's the bang (!) at the beginning? "Don't worry about that for now, Jerry replied. "You can read up on FitNesse later, and the syntax is pretty easy to get used to. Let's just concentrate on getting this fixture written. Run the test. I pushed the Test button and saw a different kind of failure.

"Good! Jerry exclaimed. "It found the fixture class. "Yeah, but it says it isn't a fixture, Avery whined. "I can fix that, Jerry said as he made the following changes to the fixture class:

"That's better! Jerry said as he pushed the Test button.

"Not much, said Avery with a smirk. "What's it looking for—a variable? I asked. "Bingo! replied Jerry, who continued typing.


"Ick! cried Avery. "A public variable! That's not a very OO construct! Jerry looked at him and said calmly, "So what? "It breaks encapsulation! Avery sputtered with righteous indignation.

"Fixture classes aren't encapsulated in the usual manner, Jerry explained. "Public variables are one of the ways we communicate with them. Anyway, this isn't the time for a lesson on the true principles of OO. Right now, we want to get this fixture done. So he pushed the Test button as Avery rolled his eyes.

Avery burst out with a huge guffaw. "Oh, great! All that work to make it look normal again! "Right! said Jerry brusquely. "Now we know that the fixture is being found and that the data is getting into it as expected. "It doesn't look as nice as it did before, I commented. "That package name dirties things up a bit. I like the way the variable name uses spaces and punctuation. Can't the fixture name do the same? "Indeed it can! Jerry replied as he opened the test page and made the following changes:

"OK, that's much nicer, I said as I looked at the display:

"Now what do we do with that date? I asked. "Good point, Jerry answered. "We need to put that date somewhere that the rest of the DTrack system can get it from.

Avery assumed a superior air and asked, "Wouldn't it be easier if DTrack just used the regular Date class to get today's date? Why do we have to invent a whole new mechanism for something so simple? "Because the tests need to control the date to make sure the application manages it correctly, Jerry snapped.

"Yeah, but that's just extra work! This has to be done in two months! Carole quickly came over, looked Avery in the eye, and said, "No, Avery, it's not extra work. We go much faster when we write these tests and build systems that are testable. You're right. We only have two months. And the only way we'll make it is if we write the tests and follow our disciplines. We've done it both ways—haven't we, Jerry? He grimaced and nodded. "As long as I'm the customer on this project, Carole continued, "we will write acceptance tests, and you will do it the way Jerry leads.

Avery had paled under Carole's tirade. "She can be a little intense at times, Jerry said calmly. "The point is that we've decided to do things this way, and if you want to be part of the team, you'll have to go along. "I still think it's a waste of time, Avery muttered under his breath. "Suspend your disbelief for awhile, Jerry answered. "Trust me; this is the best way for us to proceed. Avery shrugged and nodded, but looked at me and rolled his eyes.

"OK, I said. "Now what about that date? How does our fixture communicate it to the rest of the system, and how should the rest of the system gain access to the date?

Jerry looked at the two of us, then glanced over his shoulder at Carole, who had busied herself with Jasper. "I think it's time for a break, he replied sheepishly. "Let's get out of here for a few minutes and find a place to talk about why public variables are sometimes appropriate. So the three of us left the lab and headed for the nearest lounge.

To be continued ... Click here for past episodes and code listings. E-mail Alphonse at alphonse@sdmagazine.com.

TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK