`

JUnit In Action读书笔记(5)

阅读更多

2.3.2 Rolling your own test suite

The default TestSuite goes a long way toward keeping the simple things simple.But what happens when the default suite doesn’t meet your needs? You may want to combine suites from several different packages as part of a master suite. If you’re working on a new feature, then as you make changes, you may want to run a small set of relevant tests.(深层次解耦合,高度可配置性,佩服!)

Design patterns in action: Composite and Command Composite pattern.  "Compose objects into tree structures to represent partwhole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly. JUnit’s use of the Test interface to run a single test or suites of suites of suites of tests is an example of the Composite pattern.When you add an object to a TestSuite, you are really adding a Test, not simply a TestCase. Because both TestSuite and TestCase implement Test, you can add either to a suite. If the Test is a TestCase, the single test is run. If the Test is a TestSuite, then a group of tests is run (which could include other TestSuites).

Command pattern.  "Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations." The use of the Test interface to provide a common run method is an example of the Command pattern.



2.4 Collecting parameters with TestResult
    Newton taught that...
    Likewise,for every TestSuite,there is a TestResult.

    for "assertEquals(60,result,0);", if the result did not equal 60, JUnit would create a TestFailure object to be stored in the TestResult.

    JUnit distinguishes between failures and errors.Failure are to be expected.From time to time changes in the code (这个changes in the code具体是指?这个changes仅仅指代码层面上的错误?像拼写出错?)will cause an assertion to fail.When it does,you fix the code so the failure goes away. An error is an unexpected condition that is not expected by the test, such as an exception in a conventional program.

    Of course, an error may indicate a failure in the underlying environment.The test itself may not be broken.A good heuristic in the face of an error is the following:
        1,Check the environment.(is the database up? what about the network?)
        2,check the test.
        3,check the code.
    The TestResult is used by almost all the JUnit classes internally. As a JUnit test writer, you won’t interact with the TestResult directly; but in trying to understand how JUnit works, it’s helpful to know that it exists.    

    Design patterns in action: Collecting Parameter "When you need to collect results over several methods, you should add a parameter to the method and pass an object that will collect the results for you."  The TestResult class is an example of the Collecting Parameter pattern.

2.5 Observing results with TestListener

分享到:
评论

相关推荐

    Junit In Action 学习笔记----下载不扣分,回帖加1分,童叟无欺,欢迎下载

    第5章:探讨了将Junit整合进开发环境的各种方式。并提及了用Ant,maven和Eclipse来自动化Junit测试。 第二部分:测试策略 第6章:描述了如何用stub来执行单元测试。这一章介绍了一个连接到web服务器的示例应用,并...

    struts2自学笔记

    Struts2提供了JUnit测试支持,可以通过模拟HTTP请求来测试Action,确保业务逻辑的正确性。 在学习Struts2的过程中,配合源码阅读能够更深入理解其内部工作机制。Struts2的工具如IDEA的插件可以帮助开发者快速创建...

    struts2学习笔记

    - Struts2提供了许多插件,如Struts2-Concurrent、Struts2-Junit-plugin等,增强了框架的功能。 - OSGi支持:使Struts2可以与其他OSGi容器集成。 8. **实际应用** - 项目结构:了解如何组织Maven或Gradle项目,...

    Struts2 笔记代码

    - **测试类**:可能包含JUnit测试,用于验证Action和拦截器的正确性。 - **日志和异常处理**:如何在Struts2中配置日志框架(如Log4j),以及如何处理应用程序中的异常。 通过分析和实践这些代码,你可以深入理解...

    struts2的学习笔记+测试源代码

    Struts2提供Action测试工具,可以通过JUnit进行单元测试,确保Action的正确性。此外,Struts2的调试也很便捷,通过配置可以输出详细的日志信息,便于问题定位。 八、安全方面 尽管Struts2强大且易用,但历史上曾...

    OA项目学习笔记整合

    - 编写JUnit单元测试代码,验证业务逻辑的正确性和完整性。 - **实现呈现层**: - 根据需求设计页面流程,明确用户界面的操作步骤。 - 创建JSP页面、Action类和ActionForm类,逐步实现各个组件的功能。 #### 四...

    SSH商城项目笔记.rar

    SSH商城项目笔记主要涵盖了基于Struts2、Spring和Hibernate这三个框架构建电子商务平台的相关技术与实践。这是一套经典的Java Web开发技术组合,通常被称为SSH框架。在这个项目中,你将学习到如何运用这些技术来实现...

    北京圣思园张龙老师Struts2全部课堂笔记

    10. **测试支持**:Struts2提供了JUnit集成,使得Action类的单元测试变得简单,提高了代码质量。 以上只是Struts2框架中的一部分核心概念,通过张龙老师的笔记,我们可以更系统地学习这个框架,掌握其工作原理和...

    struts笔记.rar

    Struts2提供了JUnit测试支持,使得单元测试Action变得更加简单。 以上是关于Struts2.0的一些主要知识点。通过深入学习和实践,开发者可以有效地利用Struts2构建高效、可维护的Java Web应用。希望这些内容对你的...

    SSH笔记_ModelDriven_Prepareable

    3. 测试用例:可能包括JUnit测试,验证Action类的业务逻辑是否正确执行。 4. 运行环境配置:可能有Web服务器的配置文件,如Tomcat的server.xml,以及项目结构说明。 5. 说明文档:可能有开发者编写的README文件,...

    webwork学习笔记

    ### WebWork学习笔记知识点 #### 一、WebWork框架简介 - **定义**: WebWork是一个由OpenSymphony组织开发的MVC(Model-View-Controller)框架,专注于组件化和代码重用,适用于J2EE应用程序开发。 - **最新版本**:...

    SSH整合项目及笔记.rar

    5. **配置Hibernate**:在hibernate.cfg.xml中配置数据库连接信息,定义实体类的映射文件(hbm.xml),并生成相应的Java实体类。 6. **整合Struts与Spring**:在Struts的ActionServlet中加载Spring的...

    JAVA笔记JAVA笔记.docx

    ### JAVA笔记要点解析 #### JAVASE概述与基础概念 - **数组与数组拷贝**: - 数组是固定大小的数据结构,用于存储同种类型的数据元素。 - `java.lang.System`类中提供了静态方法`arraycopy`用于数组拷贝。此方法...

    Strtus2学习笔记

    ### Struts2学习笔记知识点梳理 #### 一、前言及背景 - **Struts2简介**:Struts2是一个基于MVC模式的开源Web应用框架,它继承了Struts1的一些特性,并在此基础上进行了很多改进,使得开发更加便捷高效。 - **学习...

    Struts2笔记

    11. **测试支持**:Struts2的Action类可以通过JUnit进行单元测试,方便进行功能验证和性能优化。 12. **工具集**:Struts2提供了丰富的工具类库,如日期时间处理、字符串操作、对象复制等,便于开发者进行日常开发...

    java基础笔记

    Java基础笔记涵盖了大量的编程概念和技术,是初学者和有经验的开发者巩固基础知识的重要参考资料。以下是对这些主题的详细解析: 1. **Java基础** Java是一种面向对象的、跨平台的编程语言,由Sun Microsystems...

    java笔记 资料收藏大师

    8. **最佳实践**:了解并遵循Java编码规范,掌握单元测试(JUnit)、持续集成(Jenkins)、版本控制(Git)等开发工具的使用,以及代码重构和性能优化技巧,这些都是提升开发效率和软件质量的关键。 以上就是标题...

    struts2笔记

    12. **测试支持**:Struts2支持单元测试和集成测试,可以使用JUnit和Mockito等工具对Action进行测试。 总之,Struts2作为一个成熟的Java web框架,提供了全面的功能和高度的可扩展性,帮助开发者构建健壮的MVC应用...

    struts2学习笔记十八(第18讲.Struts2深入探索)

    这篇学习笔记将主要围绕以下几个核心知识点展开: 1. **拦截器(Interceptors)**: Struts2的核心特性之一是拦截器,它允许开发者定义一系列的处理逻辑,这些逻辑会在Action执行前后被调用。拦截器可以用来实现如...

Global site tag (gtag.js) - Google Analytics