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
Post a Comment