Skip to content

Category Archives: UnitTest

Grails and HtmlUnit

I was struggling to add HtmlUnit to Grails to do some testing when I came upon this.
The solution was to remove the HtmlUnit included jar, xml-apis-1.3.04.
The error looked like this:

loader constraint violation: loader (instance of <bootloader>) previously initiated loading for a different type with name "org/w3c/dom/NamedNodeMap"
java.lang.LinkageError: loader constraint violation: loader (instance of ) previously initiated loading for [...]

Headless Javascript Unit Testing

I gave a presentation at work a couple of months ago covering JavaScript scoping considerations for a team of Java developers new to JavaScript.
During the presentation, I used Rhino to run the examples. I have seen other projects that use Rhino for unit testing, but they seemed a little heavy weight for what I wanted [...]

Disabling Ganymede Plugins

In Ganymede, the Manage Configuration option Eclipse users were used to using is gone. Help->Software Updates is for just that now.
So how do you go about disabling a plugin now? Well the good news is you no longer have to wait 5 minutes for the Manage Configuration window to load!
Ganymede Eclipse now provides a view, [...]

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

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 need their own instances of [...]

Commons StringUtils Is Your Friend

I have just completed a test for a method that parses a forward-slash delimited String:

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<integer> projectIdList1 =
getViewBillingReportController().parseProjectIds(PROJECTID_STR_1);
assertTrue(projectIdList1.size() == 0);
}

@Test
public void testParseProjectIds2() {
List<integer> projectIdList2 =
getViewBillingReportController().parseProjectIds(PROJECTID_STR_2);
assertTrue(projectIdList2.size() == 7);
}

@Test
public void testParseProjectIds3() [...]

Limitations of AbstractTransactionalDataSourceSpringContextTests

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 autowiring.
You write your test, run [...]

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

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 in monq.jar with a static sizeof [...]

Java Integration Testing with HSQLDB

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 point, but this is something [...]

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

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 changed and I needed to [...]

EasyMock Challenge

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 of it to run.
The documentation [...]