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.

unit testing<br />

Your first test...<br />

The first step in writing a test is to figure out what exactly it<br />

is you should be testing. Since this is testing at a really finegrained<br />

level—unit testing—you should start small. What’s<br />

the smallest test you could write that uses the order<br />

information you’ve got to store as part <strong>of</strong> the first task? Well,<br />

that’s just creating the object itself, right? Here’s how to test<br />

creating a new OrderInformation object:<br />

This is a JUnit<br />

test... a single<br />

method that tests<br />

object creation.<br />

278 Chapter 8<br />

package headfirst.sd.chapter8;<br />

import org.junit.*;<br />

public class TestOrderInformation {<br />

@Test<br />

public void testCreateOrderInformation() {<br />

OrderInformation orderInfo = new OrderInformation();<br />

}<br />

}<br />

Wait—what are you doing? There’s no way this<br />

test is going to work; it’s not even going to compile.<br />

You’re just making up class names that don’t exist.<br />

Where did you get OrderInformation from?<br />

You’re exactly right! We’re writing<br />

tests first, remember? We have no code. There’s no way<br />

this test could (or should) pass the first time through. In fact,<br />

this test won’t even compile, and that’s OK, too. We’ll fix it<br />

in a minute. The point here is that at first, your test...<br />

Download at WoweBook.Com<br />

Keep it as simple<br />

as possible: just<br />

create a new<br />

OrderInformation<br />

object.

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

Saved successfully!

Ooh no, something went wrong!