`

JUnit In Action读书笔记(3)

阅读更多

Chapter 2 Exploring JUnit

This chapter covers:
    Using the core JUnit classes
    Understanding the JUnit life cycle
++++++++++++++++++++++++
As we add new classes(这里的new classes是指像Calculator这样的实际类?), we often want to make changes to classes under test(这里的classes under test是指像TestCalculator这样继承了TestCase的类?). Of course, experience has taught us that sometimes classes (这个sometimes下的classes又是指什么?像Calculator这样的实际类?)interact in unexpected ways(这个unexpected与否是以什么为标准划分的?). So, we’d really like to keep running all of our tests on all of our classes, whether they’ve been changed or not.(上面的这个unexpected后,又怎么就非得keep running all of our tests了?又有什么逻辑支持呢?) But how can we run multiple test cases? And what do we use to run all these tests?

(虽然上面这段话有疑问,但现在似乎明白了点,实际App中的类不只是有Calculator这一个,还会有其它的类(Caller)与Calculator合作,而那些类肯定也是要测试了,这样就不能只有一个TestCalculator类了,还得有像TestCaller这样测试类.而实际App中Caller与Calculator间有联系的,在测试类里TestCalculator与TestCaller也得同时运行起来.这章就是要回答这样的问题了)


2.1 Exploring Core JUnit
    When you need to write more test cases, you create more TestCase objects(这是可以理解,那能不能在一个TestCase里同时没多个类呢?例如:在TestCalculator里有一个方法testAdd是没Calculator的add方法的,而另一个方法如testCall是没Caller里的cass方法呢?当然这样写名字与实测严重不符!不建议这样写,现在考虑的是JUnit能不能支持,也就是看这个FrameWork设计). When you need to run several TestCase objects at once, you create another object called a TestSuite. To run a TestSuite, you use a TestRunner, as you did for a singleTestCase object in the previous chapter. Figure 2.1 shows this trio in action.     

        TestCase + TestSuit + BaseTestRunner  =  TestResult

    DEFINITION
        TestCase (or test case)--A class that extends the JUnit TestCase class.
        It contains one or more tests represented by testXXX methods. A test
        case is used to group together tests that exercise common behaviors.
        In the remainder of this book, when we mention a  test, we mean a
        testXXX method; and when we mention a  test case, we mean a class
        that extends TestCase--that is, a set of tests.
        TestSuite (or test suite)--A group of tests. A test suite is a convenient
        way to group together tests that are related. For example, if you don’t
        define a test suite for a TestCase, JUnit automatically provides a test
        suite that includes all the tests found in the TestCase (more on that
        later).
        TestRunner (or test runner)--A launcher of test suites. JUnit pro-
        vides several test runners that you can use to execute your tests.
        There is no TestRunner interface, only a BaseTestRunner that all
        test runners extend. Thus when we write TestRunner we actually
        mean any test runner class that extends BaseTestRunner.


    These three classes are the backbone of the JUnit framework. Once you understand how TestCase, TestSuite, and BaseTestRunner work, you will be able to write whatever tests you need. On a daily basis, you only need to write test cases(那JUnit怎么知道什么时候用到TestSuit和BaseTestRunner呢?像现在的TestCalculator并没有用到这两个类--我现在的理解是TestCalculator没有用到.是有个叫testSuit.add()的方法? JUnit automatically provides a test suite that includes all the tests found in the TestCase ).The other classes work behind the scenes to bring your tests to life. These three classes work closely with four other classes to create the core JUnit framework.

 

2.2 Launching tests with test runners

3
1
分享到:
评论

相关推荐

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

    第3章:描述了一个复杂的TestCase,以使向你展示Junit较大的组件如何工作。这个案例中分析的是很多 应用中都有的组件:Controller.我们介绍了案例中的代码,标出哪些代码是要测试的,然后展示如何测试它。 我们...

    struts2自学笔记

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

    struts2学习笔记

    3. **Action类和结果类型** - Action类:通常继承自`ActionSupport`或自定义基类,实现业务逻辑,通过注解或XML配置与请求映射。 - 结果类型:包括JSP、FreeMarker、Stream等,用于展示Action执行后的结果。 4. *...

    Struts2 笔记代码

    3. **OGNL(Object-Graph Navigation Language)**:Struts2默认使用OGNL作为表达式语言,它允许在Action和视图之间传递数据,同时也支持在Action类中进行复杂的对象导航和计算。 4. **动态方法调用(Dynamic ...

    OA项目学习笔记整合

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

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

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

    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应用程序开发。 - **最新版本**:...

    Strtus2学习笔记

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

    SSH整合项目及笔记.rar

    3. **配置Struts**:编写struts-config.xml文件,定义Action及其跳转逻辑。配置struts.properties以指定全局属性。 4. **配置Spring**:创建ApplicationContext.xml,定义bean的装配,包括Service层和DAO层的实现。...

    java基础笔记

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

    Struts2笔记

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

    JAVA笔记JAVA笔记.docx

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

    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