Archive for the ‘UnitTest’ Category

Automated Unit Testing with DBUnit, Hsqldb in Spring & Hibernate projects

Saturday, June 7th, 2008

If your project has a lot of unit testing in Java and you use continuous builds (CruiseControl) to automate, it is often difficult to automate tests which connect to Database (Dao and integration tests). For most companies, having a dedicated Oracle schema for testing is expensive. Also, sometimes, developers ...

Commons StringUtils Is Your Friend

Wednesday, May 14th, 2008

I have just completed a test for a method that parses a forward-slash delimited String: [java] private static final String PROJECTID_STR_1 = ""; private static final String PROJECTID_STR_2 = "101/103/102/104/105/106/107"; private static final String PROJECTID_STR_3 = "///103/104"; private static final String PROJECTID_STR_4 = "a/b/102/104/105/106/107"; @Test public void testParseProjectIds1() { List projectIdList1 = getViewBillingReportController().parseProjectIds(PROJECTID_STR_1); assertTrue(projectIdList1.size() == 0); } @Test public void testParseProjectIds2() { List ...

Limitations of AbstractTransactionalDataSourceSpringContextTests

Tuesday, May 13th, 2008

This has apparently gotten a fair amount of attention over the last year or so, but I never encountered it until today- call me lucky. Here's the situation, you're using Spring MVC and you have a controller that extends another controller (A->B). Your unit test extends AbstractTransactionalDataSourceSpringContextTests, and makes use of ...

The size of an object instance at runtime - pre Java 1.5

Tuesday, November 13th, 2007

In Java 1.5, Sun provides us with a miracle method that is long overdue: long java.lang.instrument.Instrumentation.getObjectSize (Object objectToSize) However, this is still limited in that it only returns the total size of the Object, not the details about the Object size in regard to its composition. Enter monq.jar from Whatizit. There's a Sizeof class ...

Java Integration Testing with HSQLDB

Friday, May 18th, 2007

I'm a fairly recent convert to unit testing, but still when I'm under pressure to get something finished, I skip right to integration tests. Despite the guilt I still use the junit framework for these integration tests... I know the unit testing purists will be rolling their eyes at this ...

Here’s an Idea: Beanshell + EasyMock + Junit in Eclipse

Sunday, December 17th, 2006

This is postmodern computing at it's finest... I'm a fairly recent convert to test driven development. I've always thought it seemed like the right thing to do, but have only recently bought into it whole-heartedly when I took over someone else's code base and was told the requirement's have ...

EasyMock Challenge

Thursday, October 26th, 2006

I've been using EasyMock with my unit tests on a current project. Generally, it's been useful; to configure my project to run in a test environment on my desktop is a really pain. By using EasyMock I can create a very controlled environment for my tests by faking just enough ...