简体   繁体   中英

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM