什么是BDD
看看WiKi: http://en.wikipedia.org/wiki/Behavior_Driven_Development
BDD is a second-generation, outside–in, pull-based, multiple-stakeholder, multiple-scale, high-automation, agile methodology. It describes a cycle of interactions with well-defined outputs, resulting in the delivery of working, tested software that matters.
Programmer-domain examples and behavior
The same principles of examples, using contexts, events and outcomes are used to drive development at the level of abstraction of the programmer, as opposed to the business level. For instance, the following examples describe an aspect of behavior of a list:
Example 1: New lists are empty
- Given a new list
- Then the list should be empty.
Example 2: Lists with things in them are not empty.
- Given a new list
- When we add an object
- Then the list should not be empty.
请看这篇PPT:http://www.slideshare.net/shadrik/bdd-with-java-8323915
IBM之前的一篇http://www.ibm.com/developerworks/cn/java/j-cq09187/index.html
摘要:
JBehave 是用于 Java™ 平台的一个 BDD 框架,源于 xUnit 范例。正如您所料,JBehave 强调应该 这个词,而不是测试。和 JUnit 一样,您可以在自己喜欢的 IDE 中,或者通过偏爱的构建平台(例如 Ant)运行 JBehave 类。
JBehave 允许以 JUnit 的方式创建行为类;但是,在 JBehave 中,不需要扩展任何特定的基类,并且所有行为方法都需要以 should
而不是 test
开头,如清单 1 所示。
清单 1. 用于栈的一个简单的行为类
public class StackBehavior { public void shouldThrowExceptionUponNullPush() throws Exception{} public void shouldThrowExceptionUponPopWithoutPush() throws Exception{} public void shouldPopPushedValue() throws Exception{} public void shouldPopSecondPushedValueFirst() throws Exception{} public void shouldLeaveValueOnStackAfterPeep() throws Exception{} } |