Paul Michali | 21 Aug 2004 20:43
Picon
Favicon

Re: Suggestions on how to approach TDD for this problem?

J. B. Rainsberger wrote:

> I use a different approach.
> 
> public void testCreateMember() throws Exception {
>      MySqlMemberDAO memberDao = new MySqlMemberDAO();
> 
>      Member paul = Member.create(1234, "Paul Michali");
>      dao.create(paul);
> 
>      // execute query 'select count(*) from member where id=1234'
>      // assert count is 1
> }

I was wondering what your thoughts are about how to uniquely
identify members. The member number is NOT unique. In the
previous version I used the number and member's first and last
name as a primary key.

For this version, I've joined the member name parts into a
single member name field in my Member class. Should I use the
number + name as a key in the database, or use an arbitrary
unique key in the database? In reading "SQL for smarties"
the author seemed to discourage using an internally created
key. I'd just like to hear some thoughts on this from people.

In the above, I'd need to have use the number and name for
the key.

Lastly, I had a question about Member creation. In the TDD
work I did before, I created an empty Member and then the
DAO would call various add() methods to fill out each field
of the Member object, using info from the DataSource. For
example:

private void addId() {
     member.setNumber(sheet.getNumberFromTextCell(1));
}
...
private void addJoinDate() {
     member.setJoinDate(sheet.getTextDateCell(16));
}

I'd call dao.retrieve(#) and then check that the Member
had the right ID number in one test, name in another,
etc. as I fleshed out each part of the Member that was
obtained from the Spreadsheet.

I never got to a point where I needed a constructor that
had all the arguments needed to create a complete Member.

Was there something I missed in the TDD process?

Should I create this constructor to make testing of the
dao.create() capability easier?

PCM  <at>  HOME (Paul Michali)

------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/NhFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/testdrivendevelopment/

<*> To unsubscribe from this group, send an email to:
    testdrivendevelopment-unsubscribe <at> yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/


Gmane