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 Edition》
junit in action 第二版 manning出版
JUnit in Action中文版JUnit in Action中文版JUnit in Action中文版JUnit in Action中文版
Chapter 2 dives into the architecture of JUnit and shows how it’s organized. Chapter 3 we start to build a sample real-life application. Chapter 4 looks at several important aspects: the need for ...
JUnit in Action 中文版电子书
junit in action 源码 java版
JUnit in Action 3nd Edition
junit in action 中文版
JUnit in Action中文版
junit in action 第2版源码,使用maven构件工程
JunitInAction书中的源代码,便于Java开发者和测试人员使用Junit框架从代码层面进行白盒测试。
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 中文版--带目录
JUnit In Action 第二版源码 第一部分
总共有4个压缩包,这是第一个。Manning出版社09年出版的JUnit in Action第二版,貌似目前还没有中文版的。感兴趣的童鞋可以下来看看,灰常清晰。
JUnit in Action 中文版英文版 JUnit Recipies好书哦!
JUnit In Action 第二版源码 第二部分
JUnit in Action中文版,用于java单元测试
Manning的in Action,是一套非常实用的书,能够帮助读者对相关技术快速上手。 这一本是JUnit in Action第二版的,由于这不是正式发售的版本,属于测试版本,因此书中可能存在一些缺陷。