我既没有TDD也没有BDD的经验。是的,我经常为现有代码创建单元测试,但这与此处无关。而且我不能在工作中使用TDD/BDD,但想在一些业余项目中尝试。
我不确定我目前是否正确理解了TDD和BDD之间的区别。目前我只是将BDD视为进化版的TDD,其最显著的特点是能够在比TDD更高的抽象层次(用户故事)上进行工作。在TDD中,你基本上会得到相同的用户故事,但它们不像BDD那样明确。这正确吗?
就工具而言,假设上述陈述正确,对于TDD,我应该使用类似于TestNG或JUnit的东西,对于BDD,我将受益于像JBehave这样的工具。
现在问题是,我应该先从TestNG和TDD开始,只有在成功使用后才迁移到JBehave和BDD吗?还是这只是浪费时间,根本没有任何理由阻止我从一开始就尝试使用Jbehave和BDD?
更新:
在收到两个很好的回答并花费一些时间阅读有关该主题的其他资料后,我忍不住要添加一个我发现的非常好的 文章 的链接。它只是重复了下面两个问题的答案中的相同想法,但可能更详细。我最喜欢的文章部分是:
The best way to do that is to leverage BDD and TDD. Here is an approach: 1. Write requirements as user stories using the BDD grammar/structure. Do this collaboratively with the key stakeholders. 2. Enter the User Stories (feature + scenarios) in a BDD tool. 3. Write code to map the User Stories to tests. 4. Write production code using TDD to make the tests pass.
As you can see, BDD is not just TDD done right. You could use just the vocabulary of BDD to improve TDD but that would be like using only some of the benefits that BDD has to offer us. When we use the the strengths of both these techniques we will have “Software that matters” along with “Software that works”.