gorm - Why is sessionFactory not injected for unit test using Grails 3.2? -




i'm running issue unit test extends hibernatespec failing due sessionfactory not being injected service under test. whenever method on sessionfactory called during test, nullpointerexception (e.g. java.lang.nullpointerexception: cannot invoke method getclassmetadata() on null object) , test subsequently fails.

i'm using grails 3.2.4 , hibernate 5.

this working when test used @testmixin(hibernatetestmixin), looks updates, mixin deprecated , suggests using hibernatespec instead.

here's snippet test:

class testdatabaseservicespec extends hibernatespec {     def setup() {     }      def cleanup() {     }      void "test method"() {         when:          service.method()           then:         true     } } 

and here snippet service under test:

void method() { ...   table_names.add(sessionfactory.getclassmetadata('mydomain').tablename) ... } 

i have tried set service.sessionfactory in setup method setupspec method sessionfactory available in test, did not unfortunately. have thought using integration test, see if can continue have unit test work before. know if doing incorrectly or if there workaround/solution this?

thank you!

viewing source code of hibernatespec give hint. there no getsessionfactory() method in hibernate 5 grails plugin using.

i using org.grails.plugins:hibernate5:6.0.6 grails 3.2.5 , sessionfactory not null me in unit tests.

i understand not possible upgrade, give idea source of problem.

update:

service.sessionfactory = sessionfactory 

also must called in test setup.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -