Tuesday, February 10, 2009

Grails Testing Plugin often occurred exception

In previous posts (service unit testing and domain entity unit testing) I told You a lot about Grails Testing Plugin, its simple usage, but have not paid necessary accent on one often occurred exception:
"Cannot invoke method containsKey() on null object" type="java.lang.NullPointerException"

It happens then You override setUp() method but forget to call super method at first. So instead of writing:
class SomeTests extends GrailsUnitTestCase {

void setUp() {
// Some initializations.
}

}

Call super method at first:
class SomeTests extends GrailsUnitTestCase {

void setUp() {

// Call super method at first.

super.setUp()


// Some initializations.

}

}

That's all.

2 comments:

  1. Thank you so much.I was at loss trying to figure where the problem was coming from.

    ReplyDelete