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.

Good s<strong>of</strong>tware is testable...<br />

There are lots <strong>of</strong> things to think about when designing s<strong>of</strong>tware: reusability, clean APIs,<br />

design patterns, etc. Equally important is to think about your code’s testability. We’ve<br />

talked about a few measures <strong>of</strong> testability like well-factored code and code coverage.<br />

However, don’t forget that just because you have JUnit running on every commit that your<br />

code isn’t guaranteed to be good.<br />

There are a few testing bad habits you need to watch out for:<br />

A whole-lotta-nuthin’<br />

test-driven development<br />

If you’re new to test driven development it’s very easy to write a whole lot <strong>of</strong> test code<br />

but not really test anything. For example, you could write a test that places a Starbuzz<br />

order but never checks the gift card value or receipt after the order is placed “Didn’t<br />

throw an exception? Good to go.” That’s a lot like saying “it compiles—ship it.”<br />

It’s still me...<br />

In an overeager attempt to validate data it’s easy to go crazy testing fake data you fed<br />

into the system initially and miss the actual code you need to test. For example, suppose<br />

you write a test that checks that the gift card value and expiration date are correct when<br />

you call getGC() ... on our TestDBAccessor. This is a simplistic example but if<br />

you’re traversing a few layers <strong>of</strong> code with your test, it’s not too hard to forget that you<br />

put the value you’re about to test in there in the first place.<br />

Ghosts from the past<br />

You need to be extremely careful that your system is in a known state every time your<br />

automated tests kick <strong>of</strong>f. If you don’t have an established pattern for how to write your<br />

tests (like rolling back database transactions at the end <strong>of</strong> each test) it’s very easy to leave<br />

scraps <strong>of</strong> test results laying around in the system. Even worse is writing other tests that<br />

rely on these scraps being there. For example, imagine if our end-to-end testing placed<br />

an order, and then a subsequent test used the same gift card to test the “insufficient<br />

funds” test. What happens the second time this pair <strong>of</strong> tests execute? What if someone<br />

just reruns the second test? Each test should execute from a known, restorable state.<br />

There are a lot <strong>of</strong> ways to write bad tests—these are just a few <strong>of</strong> them. Pick<br />

your search engine <strong>of</strong> choice and do a search for “TDD antipatterns” to find<br />

a whole lot more. Don’t let the possibility <strong>of</strong> bad tests scare you <strong>of</strong>f, though—<br />

just like everything else, the more tests you write the better you’ll get at it!<br />

Download at WoweBook.Com<br />

you are here 4 309

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

Saved successfully!

Ooh no, something went wrong!