Java 的 BDD 框架之间有什么区别?

发布于 2024-07-25 17:27:14 字数 339 浏览 2 评论 0原文

每个 Java 行为驱动开发 (BDD) 框架的优缺点是什么?

例如,我在此处找到了其中一些。

如果我已经使用模拟库(例如 Mockito),那么使用 BDD 框架是否有意义?

What are the pros and cons of each Behavior Driven Development (BDD) framework for Java?

I've found some of them here, for example.

Does it make sense to use a BDD framework if I already use a mocking library (e.g. Mockito)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

浪漫之都 2024-08-01 17:27:15

我的团队成功地使用了 JBehave - 我们在使用 EasyB 后转向它,并发现纯文本场景文件更容易处理。

My team have used JBehave with success - we moved to it after using EasyB and found the plain text scenario files easier to deal with.

深海不蓝 2024-08-01 17:27:14

我刚刚比较了三个 Java BDD 框架。 显然我的发现的使用期限相当短。

Concordion

  • 非常灵活
  • 非常漂亮的报告输出
  • 不错的插件框架
  • 记录很差。 我必须阅读源代码才能弄清楚(幸运的是它的质量非常好)。
  • 装置似乎最终可能会与 html 紧密耦合。

EasyB

  • 学习曲线非常浅(即使对于非 Groovy 开发人员也是如此)
  • 极其强大的 DBUnit 集成
  • 显然不支持参数(导致非常模糊的故事或文本和代码之间的重复(编辑:实际上有,但它的文档隐藏得很好。)
  • 故事和代码紧密耦合(同一文件)
  • 非常基本的报告输出
  • 无法让 IntelliJ 插件工作
  • 社区不活跃(Maven 插件似乎已经损坏了三个月 - 没有太多代码示例可供借鉴)

JBehave

  • 极其强大且灵活(例如,通过预先编写故事来减少样板代码)必要条件)
  • 广泛(如果分散)的文档和示例
  • 对不同框架和环境的广泛(如果是压倒性的)支持
  • 故事文件与代码完美分离
  • 看起来有一个非常活跃的社区,并且在网络上有更多的示例和讨论。
  • 相当陡峭的学习曲线(比 Concordion/EasyB 花了我 3-4 倍的时间来弄清楚)

我没有机会像我希望的那样尝试 JDave 的 Cuke4Duke,但此时可能会推动 JBehave。

I've just finished comparing three BDD frameworks for Java. Obviously my findings have a fairly short use-by date.

Concordion

  • Very flexible
  • Very pretty report output
  • Nice plugin framework
  • Poorly documented. I had to read the source to figure it out (luckily its extremely good quality).
  • Fixtures seemed likely to end up tightly coupled to the html.

EasyB

  • Very shallow learning curve (even for non-Groovy Developers)
  • Extremely powerful DBUnit integration
  • Apparently no support for parameters (leads to either very vague stories or duplication between text and code (edit: actually there is but the documentation for it was very well hidden.)
  • Story and Code are very tightly coupled (same file)
  • Very basic report output
  • Couldn't get IntelliJ plugin to work
  • Inactive community (Maven plugin seems to have been broken for three months - not many code examples to draw on)

JBehave

  • Extremely powerful and flexible (eg reduction of boiler-plate through composition of stories as pre-requisites)
  • Extensive (if fragmented) documentation and examples
  • Extensive (if overwhelming) support for different frameworks and environments
  • Excellent separation of story files from code
  • Looks to have a pretty active community and much more examples and discussion of it on web.
  • Quite a steep learning curve (took me 3-4 times longer to figure out than Concordion/EasyB)

I didn't have the chance to try out Cuke4Duke of JDave as I would have liked, but will probably push for JBehave at this time.

芯好空 2024-08-01 17:27:14

“利弊”对于不同的人来说可能是不同的。 我通常会查看

  • 开发活动,例如是否有可能发布新版本或是否有 2 年前的最后一个版本。
  • 成熟度,例如它已经存在多久了,是否有教程甚至书籍可用。 (我不读这些书,这只是采用的标志。)
  • 工具支持,例如是否有 Eclipse 插件、Ant 支持等
  • 依赖项的大小,我不喜欢自带一切的框架。 例如,我想自己选择我的模拟框架。
  • 某种许可证,这对我来说很重要,因为我工作的公司的法律条款。
  • 与相关工具的兼容性,例如是否使用Gherkin语言。

我从一些框架中了解了

  • Instinct :最后一次活动 2010 年 3 月,:ASF 许可证
  • JDave :带有匹配器和模拟,:最后一次活动 2011 年 1 月,ASF 许可证
  • easyb 不好:最后一次活动是 2010 年 10 月,不确定:它使用 Groovy。 这可能没问题,但在我的例子中,采用会出现问题。
  • beanspec :只有一个版本2007 年,这已经死了
  • bdoc 坏:最后一次活动是 2010 年 1 月,不确定:看起来像是反其道而行之,从代码创建报告。
  • spock 不好:也许是有点极端,这是一个完整的测试框架,不仅仅是BDD,:很活跃,很酷。
  • jbehave,Java中所有BDD的“母亲”,不好:非常强大=复杂,不兼容的许可证(对我来说),几乎带有每个测试库等等,<强>好:基于RSpec,因此兼容,eclipse插件,maven集成,非常活跃的社区
  • ginkgo4j,Java 的 BDD 框架也基于 Ruby 的 RSpec,但使用Java lambda(而不是注释)允许您创建高度上下文相关、高度可读的测试。 简单的。 很强大。 开源 Apache 2 许可证。

关于模拟:您肯定还需要一个模拟框架。 BDD 框架只是帮助您编写规范,但某些测试将需要模拟或存根,尤其是。 当您自上而下设计时(从概述到细节)。

"pros and cons" might be different things for different people. I usually have a look at

  • development activity, e.g. are new releases likely or is the last release 2 years old.
  • maturity, e.g. how long has it been around, are there tutorials and maybe even books available. (I don't read these books, it's just a sign of adoption.)
  • tool support, e.g. is there an Eclipse plugin, Ant support, etc
  • size of the dependencies, I don't like frameworks that come with everything of their own. e.g. I want to chose my mocking framework myself.
  • kind of license, this is important for me because of legal terms in the company I work for.
  • compatibility with related tools, e.g. does it use Gherkin language or not.

And from some frameworks I had a look at

  • Instinct bad: last activity Mar 2010, good: ASF license
  • JDave bad: comes with matchers and mocks, good: last activity Jan 2011, ASF license
  • easyb bad: last activity Oct 2010, not sure: it uses Groovy. This might be ok, but would be a problem for adoption in my case.
  • beanspec bad: only one version in 2007, this is dead
  • bdoc bad: last activity Jan 2010, not sure: it looks like going the other way, creating a report from the code.
  • spock bad: maybe a bit extreme, this is a complete testing framework, not only BDD, good: very active, very cool.
  • jbehave, the "mother" of all BDD in Java, bad: very powerful = complex, incompatible license (for me), comes with almost every test library and much more, good: based on RSpec and therefore compatible, eclipse plugins, maven integration, very active community
  • ginkgo4j, a BDD framework for Java also based on Ruby's RSpec but using Java lambda's (instead of annotations) to allow you to create highly contextual, highly readable tests. Simple. Very powerful. Open source Apache 2 license.

Concerning the mocks: You definitely need a mocking framework as well. The BDD frameworks just help you in writing the specs, but some tests will need mocks or stubs, esp. when you design top down (from overview to detail).

三生路 2024-08-01 17:27:14

与 Java 一起使用的最佳 BDD 框架是什么? 为什么? 每个框架的优缺点是什么?

这是一个关于 Concordion 与基于 Cucumber 和 Java 的验收测试

我在这里找到了其中几个,但我不确定该选择哪一个。

确实如此,看看上面提到的那个。

如果我已经使用了模拟库(例如 Mockito),那么使用 BDD 框架是否有意义?

简短的回答:是的,当然。 实际上,使用 BDD 框架进行的验收测试和使用模拟对象进行隔离的单元测试是如此不同,以至于我并没有真正理解这个问题。 验收测试是黑盒测试,测试用于验证业务功能是否正常工作,并且最好由业务分析师编写。 使用模拟进行隔离的单元测试是白盒测试,测试用于验证单元是否正常工作并且是由开发人员编写的。 两者都很有用,但它们的目的完全不同。 换句话说,使用 Mockito 根本不会取代 BDD 框架,反之亦然。

What's the best BDD framework to use with Java? Why? What are the pros and cons of each framework?

Here is an interesting link about Concordion vs. Cucumber and Java based Acceptance Testing

I've found couple of them here, but I'm not sure which one to choose.

Really, look at the one mentioned above.

Does it make sense to use a BDD framework if I already use a mocking library (e.g. Mockito)?

Short answer: yes, definitely. Actually, acceptance testing using a BDD framework and unit testing in isolation using mock objects are so different that I don't really get the question. Acceptance testing is black box testing, tests are used to verify that a business feature is working and are ideally written by business analyst. Unit tests in isolation using mocks is white box testing, tests are used to verify that a unit is working and are written by developers. Both are useful buty they have totally different purposes. In other words, using Mockito doesn't replace a BDD framework at all and the inverse is also true.

送你一个梦 2024-08-01 17:27:14

我最初使用普通的 jUnit 进行 BDD,但最近我一直在查看 JDave 因为它几乎是 1:1我用 jUnit 做了什么。 它还在 jUnit 之上运行,因此它已经可以在 Eclipse 上运行,并且也可以轻松配置以在 Hudson 等持续集成系统上运行。 无法与其他人进行比较,但到目前为止我对 JDave 的体验一直很好。

哦,使用模拟从来都不是一个愚蠢的想法! 它们并不专门与 TDD/BDD 相关,它们的目的是减轻一般测试的负担。

I originally did my BDD with plain jUnit but I've been looking at JDave lately because it's almost 1:1 to what I was doing with jUnit. It also runs on top of jUnit so it already works on Eclipse and is also easy to configure to work on continuous integration systems such as Hudson. Can't really compare it with others but my experiences with JDave have been good so far.

Oh and it's never a stupid idea to use mocks! They're not tied to TDD/BDD specifically, their purpose is to ease the burden of testing in general.

抹茶夏天i‖ 2024-08-01 17:27:14

哇,我看到这个话题很热门,有很多好的答案……

讽刺的是,我最近发现了 BDD,并发现这个概念很有趣。 嘿,它强制编写测试......和规范! 尽管看起来令人惊讶,但后者在某些项目中也可能缺失……或者只是缺乏 BDD 强制引入的精确性。

行为驱动开发文章总结了这一概念以及一些好文章的链接(比如 Andrew Glover 写的一篇)。 此外,对于本线程的主题,它提供了相当全面的(我认为)BDD 框架列表,其中很多都是针对 Java 的。
它不能解决选择框架的问题,但至少可以简化搜索...

由于 BDD 严重依赖于测试代码的可读性,我认为一个好的选择标准是查看快速浏览/教程并了解哪一款看起来更适合您的风格。
其他标准可能是框架利用您熟悉的工具(单元测试、模拟)、IDE 的使用等等。

Wow, I see the topic is hot, lot of good answers...

Irony aside, I recently discovered BDD and found the concept interesting. Hey, it forces to write both tests... and specifications! As surprising as it might seem, the latter can be also missing in some projects... Or just lacking the precision that BDD forces to introduce.

The Behavior Driven Development article summarizes the concept and links to some good articles (like the one written by Andrew Glover). Moreover, to the topic of this thread, it gives a rather comprehensive (I suppose) listing of BDD frameworks, a good number of them being for Java.
It doesn't solve the problem of choosing the framework but at least it will ease the search...

Since BDD relies heavily on readability of test code, I suppose a good criterion of choice is to look at the quick tours/tutorial and see which one seems the more fitting your style.
Other criteria could be the fact a framework leverage tools you are familiar with (unit test, mocking), usage with IDE, and so on.

不寐倦长更 2024-08-01 17:27:14

我尝试了 Cucumber-JVM (之前开发为 Cuke4Duke)。
它使用 Gherkin DSL 进行规范,以纯文本形式存储。

Eclipse 4.2 中的 Cucumber-JVM 示例

它可以作为 JUnit 测试运行。 因此,开始使用它的唯一问题是让业务人员或产品经理在源中读/写.features。

结果

I tried Cucumber-JVM (previously developed as Cuke4Duke).
It uses Gherkin DSL for specification, stored as plain text.

Cucumber-JVM Example in Eclipse 4.2

It can be run as a JUnit test. So the only problem to start using it is to make business people or Product Manager read/write .features in Sources.

Results

迷爱 2024-08-01 17:27:14

我的团队使用 JBehave 一段时间了。 它使用纯文本文件来存储规格。 然后,每个步骤(Given、When、Then)都由某种可以从步骤中提取参数的方法执行。 场景可以缩进并且格式良好,如果客户想要验证它们,这会很有帮助。

也存在一些问题。 我们已切换到Java 6。有时在执行过程中会忽略某些场景步骤。 找出错误所在可能会带来很多麻烦。

My team have been using JBehave for some time. It uses plain text files to store specifications. Every step (Given, When, Then) is then executed by a certain method which can extract parameters from the step. Scenarios can be indented and well formatted which helps a lot if clients want to verify them.

There are some problems, too. We have switched to Java 6. Sometimes some scenario steps are ignored during execution. It may cause a lot of trouble figuring out where's the bug.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文