pojo:junit测试一

一:创建类
public class Student {
   private String name;

   Student(String name) {
      this.name = name;
   }

   String getName() {
      return name;
   }
}

二:extends junit.framework.TestCase
public class StudentTest extends junit.framework.TestCase {
   public void testCreate() {
      final String firstStudentName = "Jane Doe";
      Student firstStudent = new Student(firstStudentName);
      assertEquals(firstStudentName, firstStudent.getName());

      final String secondStudentName = "Joe Blow";
      Student secondStudent = new Student(secondStudentName);
      assertEquals(secondStudentName, secondStudent.getName());
   }
}

三:可以加hibernate测试
dao.save(firstStudent)
assertNull(dao)

你可能感兴趣的:(java,DAO,Hibernate,JUnit)