javajunit怎么写( 三 )


7. junit怎么写 下面是我做项目时的例子 , 希望对你有所帮助 。
/* *@author ougaoyan ,date:2008-10-19 */package test;import java.util.Date;import junit.framework.TestCase;import app.DA.BookDA;import app.PD.Book;public class TestBookDA extends TestCase { public TestBookDA(String name){ super(name); } // public Book(int bookID, String cip, String name, String author,String press, String category, int quantity, int reborrowable,int borrowerID,Date startDate) public void testEditBook(){ Book book1 = new Book(1,"123456" , "信号" , "张建" , "某出版社" , "电信" , 1,1,1,new Date()); Book book2 = new Book(-1,"123456" , "信号" , "张建" , "某出版社" , "电信" , 1,1,1,new Date()); Book book3 = new Book(99,"123456" , "信号" , "张建" , "某出版社" , "电信" , 1,1,1,new Date()); Book book4 = new Book(1,"123456" , "信号" , "张建" , "某出版社" , "电信" , 1,1,1,new Date()); assertEquals(true,BookDA.editBook(book1)); assertEquals(false,BookDA.editBook(book2)); assertEquals(true,BookDA.editBook(book3)); assertEquals(false,BookDA.editBook(book4)); } ////Book(int borrowerID, Date startDate, int reBorrowable, String cip) public void testAddBook(){ Book book1 = new Book(0,"234567" , "信发号" , "张建" , "某出版社" , "电信" , 1,1,1,new Date()); Book book2 = new Book(0,"123456" , "信的号" , "张建" , "某出版社" , "电信" , 1,1,1,new Date()); Book book3 = new Book(0,"99999" , "信i号" , "张建" , "某出版社" , "电信" , 1,1,1,new Date()); assertEquals(true,BookDA.addBook(book1)); assertEquals(true,BookDA.addBook(book2)); assertEquals(false,BookDA.addBook(book3)); } public static void main(String[] args) { junit.textui.TestRunner.run(TestBookDA.class); System.out.println(new TestBookDA("TestBookDA").countTestCases()); }}/* *@author ougaoyan ,date:2008-10-19 */package test;import java.util.Date;import java.util.Vector;import junit.framework.TestCase;import app.DA.CipDA;import app.PD.Cip;public class TestCipDA extends TestCase { public TestCipDA (String name){ super(name); } public void testFindBooksByName(){ String name1 = "数据库"; String name2 = "小小"; Vector vector1 = CipDA.findBooksByName(name1); Vector vector2 = CipDA.findBooksByName(name2); assertNotNull(vector1); assertNull(vector2); } public void testFindBooksByAuthor(){ String name1 = "欧阳"; String name2 = "小小"; Vector vector1 = CipDA.findBooksByAuthor(name1); Vector vector2 = CipDA.findBooksByAuthor(name2); assertNotNull(vector1); assertNull(vector2); } public void testFindBooksByCategory(){ String name1 = "计算机"; String name2 = "计 算 机"; String name3 = "wucimin"; Vector vector1 = CipDA.findBooksByCategory(name1); Vector vector2 = CipDA.findBooksByCategory(name2); Vector vector3 = CipDA.findBooksByCategory(name3); assertNotNull(vector1); assertNotNull(vector2); assertNull(vector3); } // public void testEditCip(){ // } //public Cip(String cip, String name, String author, String press,String category, int quantity, int reserverID,Date reservedDate) public void testAddCip(){ Cip cip1 = new Cip("2244" , "新加书" , "新者" , "出版社" , "计算机" , 3,0,new Date()); //Cip cip2 =new Cip(null , "新加书" , "新者" , "出版社" , "计算机" , 3,0,new Date()); Cip cip3 =new Cip("22er3rr3rt4t43t43t3t34t34t34t44" , "新加书" , "新者" , "出版社" , "计算机" , 3,0,new Date()); assertEquals(true,CipDA.addCip(cip1)); //assertEquals(false,CipDA.addCip(cip2)); assertEquals(false,CipDA.addCip(cip3)); } public void testEditCip(){ Cip cip1 = new Cip("2244" , "新加书" , "新者" , "出版社" , "计算机" , 3,0,new Date()); Cip cip2 =new Cip(null , "新加书" , "新者" , "出版社" , "计算机" , 3,0,new Date()); Cip cip3 =new Cip("22er3rr3rt4t43t43t3t34t34t34t44" , "新加书" , "新者" , "出版社" , "计算机" , 3,0,new Date()); assertEquals(true,CipDA.editCip(cip1)); assertEquals(false,CipDA.editCip(cip2)); assertEquals(false,CipDA.editCip(cip3)); }public static void main(String[] args) { junit.textui.TestRunner.run(TestCipDA.class); System.out.println(new TestCipDA("TestCipDA").countTestCases()); }}/* *@author ougaoyan ,date:2008-10-19 */package test;import java.util.Date;import java.util.Vector;import junit.framework.TestCase;import app.DA.LibManagerDA;import app.PD.LibManager;import app.PD.Student;public class TestLibManagerDA extends TestCase { public TestLibManagerDA(String name){ super(name); } public void testCheck(){ String userNa 。