We help IT Professionals succeed at work.

autowire bean in junit is possible in spring

gudii9
gudii9 asked
on
697 Views
Last Modified: 2014-05-27
Hi,

@Test
@Autowired
StudenDao studentDao;
public void saveStudentAndCoursewithBOClass() throws Exception{
DataSend datasend = new DataSend();
Student student= new Student();
student.setEmail("new@new2223.com");
student.setFirstName("new user firstname2223");
student.setLastName("new user lastname2223");      

Course pr = new Course();
String courseName="history";
pr.setCourseName(courseName);
courseDao.save(pr);

dataFeed.saveStudentAndCourse(student, courseName);



As above junit 4 test case method when i auto wire

@Autowired
StudenDao studentDao;

Eclipse is complaining i cannot do it. Where as same auto wiring i was able to do in regular java class. Does junit test case do not allow to auto-wire the bean using annotations?

please advice
Comment
Watch Question

IT Business Systems Analyst / Software Developer
CERTIFIED EXPERT
Top Expert 2015
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
oh I will try that
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.