Hi all,

I recently learned a trick from the "Pragmatic Unit Testing" book (highly 
recommended among with "The Pragmatic Programmer") that I guess may well 
worth being used in a couple places.

It is about one time set up and tear down for unit tests for things such as 
setting up a connection pool and the like, that I guess could be beneficial 
for online tests at least.

In my case it helped me reduce ArcSDEDataStoreTest from about 58 seconds to 
about 7, sounds good uh?

Following is the snippet on how to set up a test suite that performs a one 
time set up and tear down for all the test cases in a class. Of course per 
test case setup is still possible, needed and recommended, to keep test cases 
in isolation.

Regards,

Gabriel
------ Snippet:

    /**
     * Builds a test suite for all this class' tests with per suite
     * initialization directed to [EMAIL PROTECTED] #oneTimeSetUp()} and per 
suite clean 
up
     * directed to [EMAIL PROTECTED] #oneTimeTearDown()}
     * 
     * @return
     */
    public static Test suite() {
        TestSuite suite = new TestSuite();
        suite.addTestSuite(ArcSDEDataStoreTest.class);

        TestSetup wrapper = new TestSetup(suite) {
            protected void setUp() throws IOException {
                oneTimeSetUp();
            }

            protected void tearDown() {
                oneTimeTearDown();
            }
        };
        return wrapper;
    }

    private static void oneTimeSetUp() throws IOException {
        testData = new TestData();
        //loads the fixture from the .properties file
        testData.setUp();
    }

    private static void oneTimeTearDown() {
        boolean cleanTestTable = false;
        boolean cleanPool = true;
        testData.tearDown(cleanTestTable, cleanPool);
    }

    protected void setUp() throws Exception {
        super.setUp();
        this.store = testData.getDataStore();
    }
    protected void tearDown() throws Exception {
        super.tearDown();
        this.store = null;
    }


On Friday 06 July 2007 10:43:40 aaime wrote:
> Gabriel Roldán ha scritto:
> > my bad, uploaded correctly now, sorry and thanks for pointing this out.
>
> Thanks a lot Gabriel :)
> Cheers
> Andrea
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Geotools-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-devel



-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to