I test the following DAO with JUnit:
@Repository
public class MyDao {
@Autowired
private SessionFactory sessionFactory;
// Other stuff here
}
You need to add annotations to the Junit class, telling it to use the SpringJunitRunner. The ones you want are:
@ContextConfiguration("/test-context.xml")
@RunWith(SpringJUnit4ClassRunner.class)
This tells Junit to use the test-context.xml file in same directory as your test. This file should be similar to the real context.xml you're using for spring, but pointing to test resources, naturally.