tbruyelle
tbruyelle

Reputation: 13045

Grails unit testing and bootstrap

I wrote an unit test for a controller.

I have a Bootstrap file which alter the metaclass of domain classes by adding a method asPublicMap(). I use this method in the controller to return domain classes as json but only some selected public fields.

My unit test failed because of MissingMethodException for asPublicMap(). As I understood, bootstrap classes are not loaded for unit tests, only for integration tests. That's why I got this error.

My question is : Is there another place to put metaclass manipulation in order to take them into account during unit tests ?

Upvotes: 1

Views: 1055

Answers (1)

tbruyelle
tbruyelle

Reputation: 13045

Simply resolved by moving the unit test into an integration test. Bootstrap classes are loaded for integration test, so now it works well.

My concern on that migration was about the @Mock annotation, but surprisingly it works also in integration tests. The database isn't used for mocked domain classes.

Upvotes: 3

Related Questions