`

JUnit In Action读书笔记(4)

阅读更多

2.2 Launching tests with test runners
    Writing tests can be fun, but what about the grunt work of running them?
2.2.1 Selecting a test runner
    The JUnit distribution includes three TestRunner classes: one for the text console, one for Swing, and even one for AWT (the latter being a legacy that few people still use).
2.2.2 Defining your own test runner
    you could also extend this class yourself.
2.3 Composing tests with TestSuite
    ............
    Altogether, this seems simple--at least as far as running a single test case is concerned.

    But what happens when you want to run multiple test cases?Or just some of your test cases?How can you group test cases?

     JUnit’s answer to this puzzle is the TestSuite. The TestSuite is designed to run one or more test cases. The test runner launches the TestSuite; which test cases to run is up to the TestSuite.

2.3.1 Running the automatic suite
    To keep simple things simple, the test runner automatically creates a TestSuite if you don’t provide one of your own. (Sweet!)

    The default TestSuite scans your test class for any methods that start with the characters test. Internally, the default TestSuite creates an instance of your TestCase for each testXXX method. (原来是要为每一个testXXX method都新create个instance呀!佩服!!).The name of the method being invoked is passed as the TestCase constructor, so that each instance has a unique identity.
    
    For the TestCalculator, the default TestSuite could be represented in code like this:
    public static Test suite(){
          return new TestSuite(TestCalculator.class);  // (2)
    }
    (这里的并没有体现出把要测方法的名字传入TestCase的constructor里面当作unique identify吧?倒是下面的(1)处用了"testAdd",难道说JUnit能自动检测出上面的(2)处是想测"add"方法?不对吧.....)

    And this is again equivalent to the following:
      public static Test suite()
      {
          TestSuite suite = new TestSuite();
          suite.addTest(new TestCalculator("testAdd")); // --(1)
          return suite;
      }

      the automatic test suite ensures that you don’t forget to add some test to the test suite.

2.3.2 Rolling your own test suite

分享到:
评论

相关推荐

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

    第4章:讲述不同类型的软件测试以及他们在应用生命周期中扮演的角色,并讲述如何为可测试性设计。如 何实施测试先行的开发。 第5章:探讨了将Junit整合进开发环境的各种方式。并提及了用Ant,maven和Eclipse来自动化...

    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),以及如何处理应用程序中的异常。 通过分析和实践这些代码,你可以深入理解...

    OA项目学习笔记整合

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

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

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

    SSH商城项目笔记.rar

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

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

    4. **值栈(Value Stack)**:Struts2使用值栈来存储Action实例和表单数据,使得视图层可以直接访问这些对象,简化了视图与模型的交互。 5. **OGNL(Object-Graph Navigation Language)**:Struts2内部使用OGNL...

    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

    4. **配置Spring**:创建ApplicationContext.xml,定义bean的装配,包括Service层和DAO层的实现。通过Spring的AOP进行事务管理配置。 5. **配置Hibernate**:在hibernate.cfg.xml中配置数据库连接信息,定义实体类...

    Strtus2学习笔记

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

    java基础笔记

    4. **JUnit** JUnit是Java编程语言的一个单元测试框架,它使得编写和运行测试用例变得简单。JUnit主要特点: - **Test注解**:如@Test用于标记测试方法。 - **Assertions**:用于断言预期结果与实际结果是否相符...

    Struts2笔记

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

    JAVA笔记JAVA笔记.docx

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

    java笔记 资料收藏大师

    4. **Spring框架**:Spring不仅提供IoC(Inverse of Control,控制反转)和DI(Dependency Injection,依赖注入),还有AOP(Aspect-Oriented Programming,面向切面编程)。此外,Spring MVC是Spring提供的Web层...

    CXF webservice初学笔记

    - Struts2集成:CXF可以作为Struts2的Action,使服务调用更加直观。 7. **调试与测试** - CXF提供了多种工具,如CXF wsdl2java工具生成Java客户端代码,CXF Console提供Web界面监控服务状态。 - 使用JUnit进行...

    struts2笔记

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

Global site tag (gtag.js) - Google Analytics