mercredi 29 juillet 2015

Why does adding a grails Service unit test breaks controller unit tests?

Using Grails version 2.4.2

I have controller unit tests that were passing successfully. As soon as I added a MyServiceSpec that tests a MyService some controller unit tests started failing. If I comment out my MyServiceSpec tests they pass again. I have been able to narrow it down to something related to MimeType bean initialization.

If the MyServiceSpec runs then the MimeType printed using

MimeType.getConfiguredMimeTypes().each { MimeType mt ->
           println mt.name
       }

outputs

text/html

Without the MyServiceSpec it is

application/atom+xml
text/css
text/csv
application/x-www-form-urlencoded
text/html
application/xhtml+xml
text/javascript
application/json
text/json
multipart/form-data
application/rss+xml
text/plain
application/hal+json
application/hal+xml
text/xml
application/xml

Without the json mime type the responses are not rendered correctly and the tests fail. I did not see any detailed documentation on allowing or disallowing unit tests for a Service class.

Is it incorrect to have a Service level unit test? Should it be moved to integration test area? Related question is why does default MimeType configuration get wiped out for the other controller tests when Service unit test is introduced?

Aucun commentaire:

Enregistrer un commentaire