概述
示例:影片出租店程序(单元测试)
代码:
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));
}
}
最后
以上就是内向大碗为你收集整理的《重构》 — Java示例:影片出租店程序(5、单元测试)的全部内容,希望文章能够帮你解决《重构》 — Java示例:影片出租店程序(5、单元测试)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复