November 2008 - Posts

In my office, TDD is a new methodology that we've just began adopting. My senior wrote a TestCase class before he left the company. Thanks to him, I got some sample codes to study.

After baby sitting, I decided to open my computer and fire up netbeans. We're using RAD at my work btw, I could use eclipse but I like netbeans for learning something new or trying out small things. Oh, that makes me an unofficial netbeans evangelist at the same time! Lolz!

Using the JBible app I created a few weeks ago, I created a simple JUnit test class that tests one of my DAO(Data Access Object) methods.

 

What did I gain?

1. For some reason,  I actually enjoyed doing it.

2. I can now officially perform TDD at my work! Though it may take a while to improve on that. My knowledge of TDD is not so advanced afterall.

3. I don't know if it's right to say, but in netbeans you get instant profiling of your methods(if you look on the lower-left where the test status are).

 

There are probably more complicated scenarios to test against. For now, this will do for me.

Below is the code I used for testing. Please forgive the formatting. Also, if you have comments on things like how I can improve my test code, please don't hesitate to comment. I would also appreciate if you could give me pointers so I could get better at this.

Special thanks to Jop and Cruizer, though I may never become an advocate of TDD as you are guys.


package org.devpinoy.bibleapp.dao.test;

import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.devpinoy.bibleapp.dao.BibleDAO;
import org.devpinoy.bibleapp.dao.DAOHelper;
import org.devpinoy.bibleapp.dao.exceptions.NoBookFoundException;
import org.devpinoy.bibleapp.dao.impl.BibleDAOImpl;
import org.devpinoy.bibleapp.dto.Book;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

public class BibleDAOTest {

    BibleDAO bibleDAO;
   
    public BibleDAOTest() {
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    @Before
    public void setUp() {
        try {
            bibleDAO = new BibleDAOImpl(DAOHelper.getAccessDBConnection("C:/BibleDB/BibleDB.mdb"));
        }
        catch (SQLException ex) {
            Logger.getLogger(BibleDAOTest.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @After
    public void tearDown() {
        bibleDAO = null;
    }
   
    @Test
    public void bibleDAOTest(){
        assertNotNull("BibleDAO is null, everything else will fail", bibleDAO);
    }
   
    @Test
    public void getBookListTest(){
        List bookList = null;
       
        try {
            bookList = bibleDAO.getBookList();
        }
        catch (NoBookFoundException ex) {
            Logger.getLogger(BibleDAOTest.class.getName()).log(Level.SEVERE, null, ex);
        }
       
        assertNotNull("List should not be null", bookList);
        assertTrue("List should have value greater than zero", bookList.size() > 0);
       
        System.out.println("Book list size: " + bookList.size() );
       
        for (int i = 0; i < bookList.size(); i++){
            Book book = (Book)bookList.get(i);
           
            System.out.println("Book" + i + ": " + book);
           
            assertTrue("Only book instance should exist inside getBookList", book instanceof Book);
            assertNotNull("Book should not be null", book);
        }
       
    }
   
    @Test
    public void testNothing(){
        System.out.println("Testing nothing");
    }

}

 

Posted by lamia | 1 comment(s)
Filed under: , , ,

Well... It was one hell of a week for me and I needed something to remind me how fun programming is. Or used to be hehehe.

This was supposed to be an entry to Keith's contest, I unfortunately fell ill a few days before the deadline and wasn't able to continue with it. I had the change to continue working with it so rather than playing video games, I sitted and turned on my computer, and started coding. I tried to stick to my original concept eventhough I've already seen other people's submission (or screenshots).

Aside from my first statement, basically the motivation to continue with this app are the following:

1. Spread the Gospel

2. Utilize Netbean's Swing Editor, I had a lot of fun using it. I had no prior professional experience with Swing so netbeans really made up for that shortcoming.

3. Demonstrate to young and starting Java developers how a database driven Swing app might be built using Java. This is actually also my first database driven Swing application.

You can open the source in Netbeans 6.1, you need JDK 1.6 installed.

God Bless! ;)

 

UPDATE 11/03/2008: I just included an executable jar in the zip file.

You also need to place your database in C:\BibleDB\BibleDB.mdb

Enjoy!

 

 

 

Posted by lamia | 7 comment(s)
Filed under: