示例:影片出租店程序(单元测试)
注意:
(1)、使用“eclipse”自带的JUnit单元测试
(2)、使用JUnit单元测试工具实现,其中
*其中setUp()方法是构造初始化环境;
*测试方法总是以test+方法名构成;
代码:
package movie;
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);
}
}
《重构》 — Java示例:影片出租店程序(2、单元测试)
最新推荐文章于 2020-04-05 18:12:48 发布