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.

White-box testing uses inside knowledge<br />

At the deepest levels <strong>of</strong> testing, you’ll find white box tests. This is<br />

where you know exactly what’s going on inside the code, and you<br />

do your best to make that code break. If you put aside the fact that<br />

you have to fix the code when it does break, white-box testing can<br />

actually be fun: it becomes a challenge to dig into code and generate<br />

problem situations that will cause errors and crashes.<br />

When doing white-box testing you should be familiar with the code<br />

you’re about to test. You still care about functionality, but you should<br />

also be thinking about the fact that method X is going to divide<br />

by one <strong>of</strong> the numbers you’re sending in... is that number being<br />

checked properly? With white-box testing you’re generally looking<br />

for:<br />

Testing all the different branches <strong>of</strong> code. With white-box testing<br />

you should be looking at all <strong>of</strong> your code. You can see all <strong>of</strong> the if/<br />

elses and all the case and switch statements. What data do you need to<br />

send in to get the class you’re looking at to run each <strong>of</strong> those branches?<br />

Proper error handling. If you do feed invalid data into a method, are<br />

you getting the right error back? Is your code cleaning up after itself nicely<br />

by releasing resources like file handles, mutexes, or allocated memory?<br />

Working as documented. If the method claims it’s thread-safe, test the<br />

method from multiple threads If the documentation says you can pass<br />

null in as an argument to a method and you’ll then get back a certain set<br />

<strong>of</strong> values, is that what’s really going on? If a method claims you need a<br />

certain security role to call it, try the method with and without that role.<br />

Proper handling <strong>of</strong> resource constraints. If a method tries to<br />

grab resources—like memory, disk space, or a network connection—what<br />

does the code do if it can’t get the resource it needs? Are these problems<br />

handled gracefully? Can you write a test to force the code into one <strong>of</strong><br />

those problematic conditions?<br />

White-box tests tend to be code-on-code<br />

Since white-box tests tend to get up close and personal with the code they’re trying to test,<br />

it’s common to see them written in code and run on a machine rather than exercised by a<br />

human. Let’s write some code-on-code tests now...<br />

Download at WoweBook.Com<br />

testing and continuous integration<br />

White-box testing<br />

TestGoodDBAccessor<br />

+ getGC(gcId : int) :GiftCard<br />

+ saveGC(card : GiftCard) :void<br />

Order<br />

<br />

DBAccessor<br />

+ getGC(gcId : int) :GiftCard<br />

+ saveGC(card : GiftCard) :void<br />

TestInsufficientDBAccessor<br />

+ getGC(gcId : int) :GiftCard<br />

+ saveGC(card : GiftCard) :void<br />

TestInvalidDBAccessor<br />

+ getGC(gcId : int) :GiftCard<br />

+ saveGC(card : GiftCard) :void<br />

MySqlDBAccessor<br />

+ getGC(gcId : int) :GiftCard<br />

+ saveGC(card : GiftCard) :void<br />

you are here 4 243<br />

DB<br />

check balances, etc.<br />

saveOrder(...) insert into ...<br />

saveGC(...)<br />

update amnt ...<br />

Most code works<br />

great when things are<br />

going as expectedthe<br />

so-called “happy<br />

path”-but what<br />

about when things go<br />

<strong>of</strong>f-track?<br />

Black-box testing<br />

looked at error<br />

messages, but what<br />

about what the code<br />

left around when<br />

things go wrong?<br />

That’s for whitebox<br />

testing to<br />

examine.

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

Saved successfully!

Ooh no, something went wrong!