01.02.2013 Views

Software Development Cross Solution - Index of - Free

Software Development Cross Solution - Index of - Free

Software Development Cross Solution - Index of - Free

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

all green, you’re done<br />

It’s not easy bein’ green...<br />

You did it—through the help <strong>of</strong> the strategy pattern, dependency injection (see the previous No<br />

Dumb Questions), and mock objects, you have a really powerful, but not too bulky, suite <strong>of</strong> unit<br />

tests. You now have piles <strong>of</strong> tests that make sure your system does what it’s supposed to be doing<br />

at all times. So to keep your system in line:<br />

1<br />

2<br />

3<br />

4<br />

5<br />

310 Chapter 8<br />

Always write a test before you write the real production code.<br />

Make sure your test fails, and then implement the simplest thing that will<br />

make that test pass.<br />

Each test should really only test one thing; that might mean more than one<br />

assertion, but one real concept.<br />

Once your’re back to green (your test passes) you can refactor some<br />

surrounding code if you saw something you didn’t like. No new<br />

functionality—just cleanup and reorganization.<br />

Start over with the next test. When you’re out <strong>of</strong> tests to write, you’re done!<br />

When all <strong>of</strong> your tests pass, you’re done<br />

Before we never really had a way <strong>of</strong> knowing when we were finished. You wrote a bunch <strong>of</strong><br />

code, probably ran it a few times to make sure it seemed to be working, and then moved on.<br />

Unless someone said something bad happened, most developers won’t look back. With testdriven<br />

development we know exactly when we’re done—and exactly what works.<br />

I’m pretty sure I’m done.<br />

Things seem to be working OK.<br />

Bob again...<br />

Which do you think is better?<br />

vs<br />

File Edit Window Help Bliss<br />

hfsd> java -cp junit.jar;. org.junit.runner.JUnitCore<br />

headfirst.sd.chapter8.TestOrderProcessor<br />

JUnit version 4.4<br />

. . . . . . . . . . . . . . . . . . . . . . . . . . . . .<br />

. . . . . . . . . . . . . . . . . . . . . . . . . . . . .<br />

. . . . .<br />

Time: 0.321<br />

OK (86 test)<br />

hfsd><br />

Download at WoweBook.Com<br />

Our test suite in action<br />

* If you said Bob, please donate this book to your library.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!