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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Red, green, refactor...<br />

Seriously? You made an empty class to get a test<br />

to pass and you call that SUCCESS?<br />

Test-driven development is about<br />

doing the simplest thing you can to<br />

get your test to pass.<br />

Resist the urge to add anything you might need in the<br />

future. If you need that something later, you’ll write<br />

a test then and the code to pass that test. In the<br />

meantime, leave it alone. Obviously you can’t stop<br />

here—you need to move on to the next test—but<br />

focusing on small bits <strong>of</strong> code is the heart and<br />

soul <strong>of</strong> test-driven development.<br />

Test-driven development works on a very simple cycle:<br />

When you’re done refactoring,<br />

move on to the next test and<br />

go through the cycle again.<br />

1<br />

2<br />

3<br />

test-driven development<br />

This is the YAGNI<br />

principle... You Ain’t<br />

Gonna Need It.<br />

Red: Your test fails.<br />

First you write a test that checks whatever functionality you’re about to<br />

write. Obviously it fails, since you haven’t implemented the functionality<br />

yet. This is the red stage, since your test GUI probably shows the test<br />

in red (failing).<br />

Green: Your test passes.<br />

Next, implement the functionality to get that test to pass. That’s it. No<br />

more. Nothing fancy. Write the simplest code you can to get your test<br />

to pass. This is the green stage.<br />

Refactor: Clean up any duplication, ugliness, old code, etc.<br />

Finally, after your test passes, you can go back in and clean up some<br />

things that you may have noticed while implementing your code. This<br />

is the refactor stage. In the example for Starbuzz, you don’t have any<br />

other code to refactor, so you can go right on to the next test.<br />

Download at WoweBook.Com<br />

you are here 4 281

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

Saved successfully!

Ooh no, something went wrong!