Unit Testing Spring @Repository & Hibernate -


i'm new spring.

in past when use hibernate. can test dao because automatically sessionfactory.

but when using spring (@repositry , @entity) only.

i can't seems unit test code because .gethibernatetemplate() keeps return null.

i suspect hibernatesession not initialize.

may know spring, how can unit test against database?

without code example can speculate. test repositories / entities unit test class requires spring context initalised.

@runwith(springjunit4classrunner.class) @contextconfiguration(locations="classpath:meta-inf/test-context.xml") public class yourtestclass {     @autowired     <<autowire repository/sessionfactory>>   } 

fyi: test-context.xml assumes have configured spring beans via xml , not javaconfig.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -