Agile Java 书中的例子用JUnit 3 写成, 学习过程中顺便应用一下JUnit 4。
Lesson 2 - Suites 一节
import junit.framework.TestSuite;
public class AllTests {
public static TestSuite suite() {
junit.framework.TestSuite suite =
new junit.framework.TestSuite();
suite.addTestSuite(StudentTest.class);
suite.addTestSuite(CourseSessionTest.class);
return suite;
}
}
由于JUnit4 添加了Annotation支持 简化了TestSuite的写法 。 只需如此:
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({StudentTest.class, CourseSessionTest.class})
public class AllTests { }
The setUp
Method 一节
TestCase中测试方法公用的初始化代码放在setUp()中
public class CourseSessionTest extends TestCase {
private CourseSession session;
@Override
public void setUp() {
session = new CourseSession("ENGL", "101");
}
//...
}
对JUnit4 初始化方法的名字可以任选,只要使用@Before指明”这是执行test之前需要运行的代码“即可
public class CourseSessionTest {
private CourseSession session;
@Before
public void anyMethod() {
session = new CourseSession("ENGL", "101");
}
//...
}
Caution!session本来是在测试方法内初始化的,抽出来以后记得把那些方法里的CourseSession session改掉…
More Refactoring 一节
测试代码中引入的List 就是对实现代码的一种设计, 最终还要引入到生产代码中去。
保持良好的封装,与客户代码减少耦合——测试代码中并不需要得到allStudents的List,只是需要list中的各个元素。此时,应该把List的实现代码移入CourseSession类中,只暴露get方法,防止客户代码对这个List进行修改。
分享到:
相关推荐
高清版本
object.ObjectUtil中的对象深度转换能力,方法为ObjectUtil.to 该能力是Agile系列框架高代码复用率的根本所在
Agile Java Crafting Code with Test-Driven Development英文版,包含pdf和chm格式,pdf格式的目录缩进和超连接有问题,所以附上了改造过的chm文件,以便有心人可以修改目录。
Agile-Data-Warehouse-Design-From-Business-Models-to-BI-Models 敏捷数据仓库开发, presentation文档
agile java-驱动测试开发的编程技术-带超详细书签目录.pdf 本资源转载自网络,供学习研究之用,如用于商业用途,请购买正版,如有侵权,请联系我或CSDN删除。
agile-bpm-basic-master.zip
Wi-Fi-Agile-Multiband-Technical-Specification-v1.4
Agile Java Development with Spring, Hibernate and Eclipse 这个是代码,书也在我的资源里。
python库。 资源全名:agile-analytics-0.5.tar.gz
标签:agile-eci-base.jar.zip,agile,eci,base,jar.zip包下载,依赖包
多个敏捷团队之间的版本控制(Agile-version-control-with-multiple-teams-InfoQ-v1.3)
“Lean-Agile Acceptance Test-Driven Development tells a tale about three fictive project stakeholders as they use agile techniques to plan and execute their project.
信息安全_数据安全_dev-r04-agile-and-continuous-thr 网络犯罪 信息保护 基础设施 信息安全 威胁情报
标签:agile-swing-base.jar.zip,agile,swing,base,jar.zip包下载,依赖包
开源项目-agile-leaf-50mm.zip,基于golang的web图像库应用程序。
标签:agile-share-xml.jar.zip,agile,share,xml,jar.zip包下载,依赖包
标签:agile-share-prof.jar.zip,agile,share,prof,jar.zip包下载,依赖包
标签:agile-share-base.jar.zip,agile,share,base,jar.zip包下载,依赖包
Agile Java 中文版 优秀的入门书籍之一