SSH Junit4测试

 

package test;



import static org.junit.Assert.*;



import java.util.List;



import org.hibernate.SessionFactory;

import org.junit.Ignore;

import org.junit.Test;

import org.springframework.context.support.ClassPathXmlApplicationContext;



import bean.CalendarEvent;

import dao.CalendarEventDao;



public class CalendarEventDaoTest {



    @Test

    public void testInsetCalendarEvent() {

       ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

       SessionFactory sessionFactory = (SessionFactory) context.getBean("sessionFactory");

       CalendarEventDao dao=new CalendarEventDao(sessionFactory);

       CalendarEvent event=new  CalendarEvent();

       event.setEdate("2015-7-16");

       event.setEcontent("学习");

       boolean flag=dao.insetCalendarEvent(event);

       assertEquals(true, flag);

    }



    @Ignore

    public void testGetCalendarEvent() {

         ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

         SessionFactory sessionFactory = (SessionFactory) context.getBean("sessionFactory");

         CalendarEventDao dao=new CalendarEventDao(sessionFactory);

         List<CalendarEvent> list=dao.getCalendarEvent();

           for (int i = 0; i < list.size(); i++) {

            System.out.println(list.get(i).getEid()+";"+list.get(i).getEcontent());

        }

           assertEquals(3, list.size());

    }



}

结果:

SSH Junit4测试

你可能感兴趣的:(JUnit4)