`
akunamotata
  • 浏览: 378723 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

junit in action 2nd note

    博客分类:
  • note
阅读更多

The @Before and @After annotated methods are executed right before/after the
execution of each one of your @Test methods and regardless of whether the test
failed or not. This helps you to extract all of your common logic, like instantiating
your domain objects and setting them up in some known state. You can have as
many of these methods as you want, but beware that if you have more than one of
the @Before/@After methods, the order of their execution is not defined.

JUnit also provides the  @BeforeClass and  @AfterClass annotations to anno-
tate your methods in that class. The methods that you annotate will get exe-
cuted, only once, before/after all of your  @Test methods. Again, as with the
@Before and  @After annotations, you can have as many of these methods as
you want, and again the order of the execution is unspecified.

both the @Before/@After and @BeforeClass/@After-
Class annotated methods must be  public. The  @BeforeClass/@AfterClass
annotated methods must be public and static.


JUnit best practices: unit test one object at a time

JUnit best practices: choose meaningful test method names
a good rule is to start with the testXXX naming scheme, where XXX is the name of
the domain method to test.

JUnit best practices: explain the failure reason in assert calls

JUnit best practices: one unit test equals one @Test method

JUnit best practices: test anything that could possibly fail

JUnit best practices: let the test improve the code

JUnit best practices: make exception tests easy to read

JUnit provides us with another parameter to the @Test annotation
called timeout. In this parameter, you can specify your time barrier in terms of milli-
seconds, and if the test takes more time to execute, JUnit will mark the test as failed.

it’s good to skip some of the tests."@Ignore"

JUnit best practice: always specify a reason for skipping a test

In JUnit 4, when you annotate methods with @Ignore, you
get statistics that include how many tests JUnit skipped in addition to how many tests
passed and failed.

JUnit best practices: same package, separate directories

分享到:
评论

相关推荐

    junit in action 2nd edtion

    ### JUnit in Action 第二版知识点详述 #### 一、JUnit概述与重要性 - **JUnit简介**:JUnit是一款广泛应用于Java领域的单元测试框架,主要用于编写和运行可重复的测试案例,帮助开发者确保代码质量并提高软件开发...

    JUnit in Action 3nd Edition

    "JUnit in Action 3rd Edition" JUnit是一种流行的Java单元测试框架,由Kent Beck和Eric Gamma于1997年创立。JUnit在软件测试领域中扮演着重要的角色,帮助开发者编写高质量的代码。下面是关于JUnit的重要知识点: ...

    JUnit in Action(JUnit经典书籍)中文+英文

    《JUnit in Action》是一本专为Java开发人员深入理解单元测试框架JUnit而编写的经典书籍。本书详尽地探讨了如何有效地使用JUnit进行软件测试,包括基础概念、高级特性和最佳实践,旨在帮助读者提升软件质量,降低...

    Junit in action 2nd edition

    ### JUnit in Action 第二版 关键知识点综述 #### 一、绪论与入门 (Chapter 1) 在第一章中,作者们迅速带领读者进入JUnit的世界。本章旨在为读者提供一个快速上手的指南,确保即便是初学者也能快速理解JUnit的基本...

    JUnit in Action中文版

    JUnit in Action中文版JUnit in Action中文版JUnit in Action中文版JUnit in Action中文版

    JUnit in Action 中文版电子书

    《JUnit in Action 中文版》是一本专注于Java测试框架JUnit的专业书籍,旨在帮助读者深入了解和熟练运用JUnit进行单元测试。JUnit作为Java开发中不可或缺的工具,对于保证代码质量、提高软件可维护性起到了至关重要...

    junit in action 中文版

    junit in action 中文版

    junit in action 第2版源码part1

    junit in action 第2版源码,使用maven构件工程

    JUnit in Action中文版.

    《JUnit in Action中文版》是一本深入探讨Java单元测试框架JUnit的专业书籍,旨在帮助开发者熟练掌握使用JUnit进行软件测试的方法和技术。JUnit是Java领域最广泛使用的单元测试框架,它简化了编写、运行和分析测试...

    JunitInAction源代码2

    JunitInAction书中的源代码,便于Java开发者和测试人员使用Junit框架从代码层面进行白盒测试。

    junit in action 源码

    《JUnit in Action》是一本广泛认可的Java单元测试框架JUnit的实战指南,它深入浅出地介绍了如何有效地使用JUnit进行软件测试。这本书的源码包含了书中提到的各种示例和实践案例,是学习和理解JUnit功能及其实现原理...

    JUnit in Action

    JUnit in Action is an example-driven, how-to book on unit-testing Java applications, including J2EE applications, using the JUnit framework and its extensions. This book is intended for readers who ...

    JUnit_in_Action,_2nd_Edition.pdf

    ### JUnit in Action, 2nd Edition - 关键知识点概览 #### 一、书籍简介与价值 《JUnit in Action, 2nd Edition》是一本深入介绍JUnit框架的专业书籍,适用于希望提高单元测试技能和软件质量意识的程序员。本书由...

    JUnit In Action的源代码

    《JUnit In Action》是一本专注于Java测试框架JUnit的实战书籍,源代码的提供是为了让读者更好地理解和实践书中介绍的各种测试技术和方法。JUnit是Java开发者进行单元测试的重要工具,它的使用和理解对于提升软件...

    JUnit In Action 第二版源码

    JUnit In Action 第二版源码 第一部分

    Junit in Action 中文版

    《JUnit in Action》是一本专为Java开发者设计的单元测试指南,它深入介绍了如何有效地使用JUnit框架进行软件质量保证。本书以中文版的形式提供,旨在帮助中国的开发者更好地理解和应用单元测试这一关键的软件开发...

    JUnit in action JUnit Recipies

    《JUnit in Action》和《JUnit Recipes》是两本关于Java单元测试的重要书籍,它们深入浅出地介绍了如何使用JUnit框架进行高效、可靠的测试。JUnit是一个流行的开源测试框架,广泛用于Java应用程序的单元测试,它提供...

Global site tag (gtag.js) - Google Analytics