示例:影片出租店程序(单元测试)
代码:
package Movie_Ref;
import junit.framework.TestCase;
public class MovieTest extends TestCase {
protected void setUp() throws Exception {
super.setUp();
}
public void testStatement() {
String S = "Rental Record for ZhangSan/n"
+ "/taaa/t2.0/n"
+ "/tbbb/t3.0/n"
+ "/tccc/t1.5/n"
+ "Amount owed is 6.5/n"
+ "You earned 3 frequent renter points";
Customer customer = new Customer("ZhangSan");
customer.addRental(new Rental(new Movie("aaa",Movie.REGULAR),1));
customer.addRental(new Rental(new Movie("bbb",Movie.NEW_RELEASE),1));
customer.addRental(new Rental(new Movie("ccc",Movie.CHILDRENS),1));
String S1 = customer.statement();
assertTrue(S.equals(S1));
//System.out.println(S);
//System.out.println(S1);
}
public void testHtmlStatement() {
String S = "<H1>Rentals for <EM>ZhangSan</EM></H1><P>/n"
+ "aaa: 2.0<BR>/n"
+ "bbb: 3.0<BR>/n"
+ "ccc: 1.5<BR>/n"
+ "<P>You owe <EM>6.5</EM><P>/n"
+ "On this rental you earned <EM>3 </EM> frequent renter points<P>";
Customer customer = new Customer("ZhangSan");
customer.addRental(new Rental(new Movie("aaa",Movie.REGULAR),1));
customer.addRental(new Rental(new Movie("bbb",Movie.NEW_RELEASE),1));
customer.addRental(new Rental(new Movie("ccc",Movie.CHILDRENS),1));
String S1 = customer.htmlStatement();
assertTrue(S.equals(S1));
}
}