BDD 测试是验收测试吗?

发布于 2024-07-18 04:38:59 字数 67 浏览 7 评论 0原文

如果您有 BDD 测试,您是否需要像 Fitnesse 这样的东西?

Do you need something like Fitnesse, if you have BDD tests?

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

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

发布评论

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

评论(7

燃情 2024-07-25 04:38:59

BDD“测试”存在于多个不同的粒度级别,一直到最初的项目愿景。 大多数人都知道这些场景。 有些人还记得 BDD 以“应该”一词开头作为 JUnit 的“测试”的替代品“ - 作为 TDD 的替代品。 我将“测试”放在引号中的原因是因为 BDD 并不是真正关于测试;而是关于测试。 它的重点是发现缺乏理解或不匹配的地方。

由于这种关注,对话比 BDD 工具重要得多。

我要再说一遍。 对话比 BDD 工具重要得多。

验收测试实际上并不强制进行对话,并且通常假设您正在编写的测试是正确的测试。 在 BDD 中,我们假设我们不知道自己在做什么(并且可能不知道我们不知道)。 这就是为什么我们使用“给定、何时、那么”之类的东西 - 这样我们就可以围绕场景和/或单元级示例进行对话。 (这是大多数人熟悉的两个级别 - 相当于验收测试和单元测试 - 但它的规模有所扩大)。

我们不称其为“验收测试”,因为您不能要求业务人员“请帮助我进行验收测试”。 他们会用一种非常奇怪的眯眼目光看着你,然后将你视为那个极客女孩。 93% 的人不希望这样。

尝试“我想和你谈谈……的场景”。 或者,“你能给我举个例子吗?” 这些都很好。 将它们称为“验收测试”开始让人们认为您实际上在进行测试,这意味着您知道自己在做什么并且只是想确保已经完成了它。 那时,谈话的重点往往是你能多快地找出错误的东西,而不是你正在找出错误的东西这一事实。

而你却搞错了事情。 真的,老实说,你是。即使你认为你'不是,那只是因为你不了解二阶无知。 你不知道自己不知道,这没关系,只要你找到了你可以知道自己不知道的地方。 (您不会找到所有这些。不要让分类悖论让您彻夜难眠。)

真正做到正确的唯一方法是预先了解所有需求,然后您知道当你尝试这样做时会发生什么。 这是正确的。 这是瀑布。 还记得加班吗? 周末上班吗? 在这七年里,你创造的任何东西都没有投入生产? 如果你想避免这种情况,你只有一次机会:假设你错了,进行一些对话以减少错误,然后接受你仍然是错误的事实并继续努力。 太早编写测试意味着你有更多的机会犯错,现在更难改变,每个人都认为你是对的,PM正在衡量你的速度,现在你注定会犯错再坚持两周。 而且 - 更糟糕的是 - 你也将测试你是否错了。

再次。 对话比 BDD 工具重要得多。

请不要只关注工具。 这些工具只是一种捕获对话并确保它们融入代码的机制。 场景不能替代对话,就像 3 x 5 索引卡不能替代需求一样。

话虽如此,如果您必须从一个工具开始,请将 Slim 放在 Fitnesse 后面,这样它就可以运行可爱的给定/何时/然后,而不必弄乱 Fit 的表格和固定装置。 GivWenZen 基于 Slim,两者都很棒。 FitSharp 对于 .NET 领域的人来说是等价的。 或者只是使用 Cucumber、SpecFlow,或者 敲一个小型定制 DSL* 可以在多年内很好地完成工作。

透明度:*那是我写的。 还有一些 JBehave。 我希望我们将其称为“不要集中精力于 BDD 工具行为”。 我可能会大量参与 BDD 的其他部分。 另外,如果我能把这个消息传达出去,丹·诺斯会给我买一品脱啤酒,所以这并不是完全公正的建议。

无论如何 - 已经进行对话了。 这只是人。 去谈谈吧。

BDD "tests" exist at multiple different levels of granularity, all the way up to the initial project vision. Most people know about the scenarios. A few people remember that BDD started off with the word "should" as a replacement for JUnit's "test" - as a replacement for TDD. The reason I put "tests" in quotes is because BDD isn't really about testing; it's focused on finding the places where there's a lack or mismatch of understanding.

Because of that focus, the conversations are much more important than the BDD tools.

I'm going to say that again. The conversations are much more important than the BDD tools.

Acceptance testing doesn't actually mandate the conversations, and usually works from the assumption that the tests you're writing are the right tests. In BDD we assume that we don't know what we're doing (and probably don't know that we don't know). This is why we use things like "Given, When, Then" - so that we can have conversations around the scenarios and / or unit-level examples. (Those are the two levels most people are familiar with - the equivalent of acceptance tests and unit tests - but it goes up the scale).

We don't call them "acceptance tests" because you can't ask a business person "Please help me with my acceptance test". They'll look at you with a really weird, squinty gaze and then dismiss you as that geek girl. 93% of you don't want that.

Try "I'd like to talk to you about the scenario where..." instead. Or, "Can you give me an example?" Either of these are good. Calling them "Acceptance tests" starts making people think that you're actually doing testing, which would imply that you know what you're doing and just want to make sure you've done it. At that point, conversations tend to focus on how quickly you can get the wrong thing out, instead of about the fact you're getting out the wrong thing.

And you're getting the wrong thing out. Really, honestly, you are. Even if you think you're not, it's only because you don't understand second-order ignorance. You don't know that you don't know, and that's OK, as long as you've found the places where you could know you don't know. (You won't find all of them. Don't let the categorisation paradox keep you up at night.)

The only way to really get it right is to get all the requirements up front, and you know what happens when you try that. That's right. It's Waterfall. Remember the overtime? The weekend work? The seven years in which not one thing you created made it to production? If you want to avoid that, you only have one chance: assume you're wrong, have some conversations about it to be less wrong, then accept that you're still wrong and go for it anyway. Writing tests too early means you have even more chance to be wrong, and now it's harder to change and everyone thinks you're right and the PM is measuring your velocity and now you're committed to being wrong for another 2 weeks. And - worse - you're about to test that you're wrong, too.

Once again. The conversations are much more important than the BDD tools.

Please, please, don't fixate on the tools. The tools are just a mechanism for capturing the conversations and making sure that they get played into the code. Scenarios are not a replacement for conversations, any more than a 3 x 5 index card is a replacement for requirements.

Having said that, if you must start with a tool, put Slim behind Fitnesse so that it can run lovely Given / When / Thens without having to mess with Fit's tables and fixtures. GivWenZen is based on Slim and either of them rocks. FitSharp is the equivalent for those of you in the .NET space. Or just use Cucumber, or SpecFlow, or knock up a little custom DSL* that will do the job fine for years.

Transparency: *I wrote that one. And bits of JBehave. I wish we had called it "Dont-concentrate-on-BDD-tools-Behave". I might be heavily involved in other bits of BDD. Plus Dan North will buy me a pint if I can get this message out, so it's not exactly impartial advice.

Regardless - have the conversations already. It's just people. Go talk.

病女 2024-07-25 04:38:59

严格来说,我不知道是否存在“BDD 测试”这样的东西。 BDD 是一种哲学,它建议您如何最好地与利益相关者进行交互和协作以完成复杂的项目。 它并不直接规定编写测试的最佳方式。 换句话说,您可能仍然需要在 BDD 哲学项目下进行所有常见类型的测试(包括验收测试)。

当您听到“BDD 框架”时,说话者通常指的是用于编写所有常用类型的测试但具有 BDD 风格的框架。 例如,在 RSpec 中,您仍然编写单元测试; 你只需将 BDD 风格添加到其中即可。

I don't know if there's such a thing, strictly speaking, as a "BDD test". BDD is a philosophy that suggests how you can best interact and collaborate with stakeholders to complete a complex project. It doesn't directly make any prescriptions for the best way to write tests. In other words, you'll probably still have all the usual kinds of tests (including acceptance tests) under a BDD-philosophy project.

When you hear of "BDD frameworks", the speaker usually means a framework for writing all your usual kinds of tests but with a BDD twist. For example, in RSpec, you still write unit tests; you just add the BDD flavor to them.

想念有你 2024-07-25 04:38:59

虽然 BDD 的范围比单纯的测试更大,但确实存在 BDD 测试。 这些测试是遵循 BDD 语言的单元测试。

给定一些初始上下文(给定的),
当事件发生时,
然后确保一些结果。

根据您的偏好语言,有一些不错的 BDD 框架可供使用。
用于 Java 的 JBehave
用于 Ruby 的 RSpec
NBehave for .NET

While BDD is larger than the scope of just tests, there are indeed BDD tests. These tests are Unit Tests that follow the BDD language.

Given some initial context (the givens),
When an event occurs,
then ensure some outcomes.

There are a few good BDD frameworks available depending on your language of preference.
JBehave for Java
RSpec for Ruby
NBehave for .NET

并安 2024-07-25 04:38:59

我喜欢区分“规格”和“测试”。

如果我要介绍一个名为 GetAverage(IEnumerablenumbers) 的方法,我将编写一个或多或少标准的单元测试。

如果我要介绍一个名为 CalculateSalesTax(decimal amount, State state, Municipality cityity) 的方法,我仍然要编写单元测试,但我将其称为规范,因为我要对其进行更改 (1) 以验证例程的行为,以及 (2) 因为测试本身将记录例程及其验收标准。

考虑:

[TestFixture]
public class When_told_to_calculate_sales_tax_for_a_given_state_and_municipality() // the name defines the context
{
    // set up mocks and expected behaviour
    StateSalesTaxWebService stateService 
        = the_dependency<IStateSalesTaxWebService>;
    MunicipalSurchargesWebService municipalService 
        = the_dependency<IMunicipalSurchargesWebService>;

   stateService.Stub(x => x.GetTaxRate(State.Florida))
        .Return(0.6);
    municipalService.Stub(x => x.GetSurchargeRate(Municipality.OrangeCounty))
        .Return(0.05);

    // run what's being tested
    decimal result = new SalesTaxCalculator().CalculateSalesTax
        (10m, State.Florida, Municipality.OrangeCounty);

    // verify the expected behaviour (these are the specifications)
    [Test]
    public void should_check_the_state_sales_tax_rate()
    {
        stateService.was_told_to(x => x.GetTaxRate(State.Florida)); // extension methods wrap assertions
    }

    [Test]
    public void should_check_the_municipal_surcharge_rate()
    {
        municipalService.was_told_to(x => x.GetSurchargeRate(Municipality.OrangeCounty));
    }

    [Test]
    public void should_return_the_correct_sales_tax_amount()
    {
        result.should_be_equal_to(10.65m);
    }
}

I like to draw a distinction between "specs" and "tests."

If I am covering a method called GetAverage(IEnumerable<int> numbers), I am going to write a more or less standard unit test.

If I am covering a method called CalculateSalesTax(decimal amount, State state, Municipality municipality), I am still going to write the unit test, but I'll call it a specification because I'm going to change it up (1) to verify the behaviour of the routine, and (2) because the test itself will document both the routine and its acceptance criteria.

Consider:

[TestFixture]
public class When_told_to_calculate_sales_tax_for_a_given_state_and_municipality() // the name defines the context
{
    // set up mocks and expected behaviour
    StateSalesTaxWebService stateService 
        = the_dependency<IStateSalesTaxWebService>;
    MunicipalSurchargesWebService municipalService 
        = the_dependency<IMunicipalSurchargesWebService>;

   stateService.Stub(x => x.GetTaxRate(State.Florida))
        .Return(0.6);
    municipalService.Stub(x => x.GetSurchargeRate(Municipality.OrangeCounty))
        .Return(0.05);

    // run what's being tested
    decimal result = new SalesTaxCalculator().CalculateSalesTax
        (10m, State.Florida, Municipality.OrangeCounty);

    // verify the expected behaviour (these are the specifications)
    [Test]
    public void should_check_the_state_sales_tax_rate()
    {
        stateService.was_told_to(x => x.GetTaxRate(State.Florida)); // extension methods wrap assertions
    }

    [Test]
    public void should_check_the_municipal_surcharge_rate()
    {
        municipalService.was_told_to(x => x.GetSurchargeRate(Municipality.OrangeCounty));
    }

    [Test]
    public void should_return_the_correct_sales_tax_amount()
    {
        result.should_be_equal_to(10.65m);
    }
}
病女 2024-07-25 04:38:59

JBehave(和 NBehave 最近添加了相同的支持)使用常规测试文件,因此虽然许多其他框架添加了“BDD 品味单元测试”,但使用 JBehave 创建的基于文本的行为规范/示例适合验收测试。 不,你不需要为此进行健身。

为了了解它是如何工作的,我建议JBehaves 2min 教程

JBehave (and NBehave recently added the same support) work with regular test files so while many other frameworks add "BDD taste tounit tests" the text based behaviour specifications/examples created with JBehave are suitable for acceptance tests. And no, you don't need fitnesse for that.

To get an idea of how it works I suggest JBehaves 2min tutorial.

路弥 2024-07-25 04:38:59

对于 Flex 中的 BDD 测试,您可以尝试 GivWenZen-flex 查看 http://bitbucket.org/loomis/ givwenzen-flex

干杯,
克里斯

For BDD testing in Flex you can try GivWenZen-flex check it out http://bitbucket.org/loomis/givwenzen-flex.

Cheers,
Kris

哆兒滾 2024-07-25 04:38:59

良好实施的 xBehavior BDD 测试是机器人驱动的用户接受标准。

xSpecification BDD 测试通常是单元测试,不太可能成为可接受的用户验收标准。

xBehavior BDD tests implemented well are robo-driven user acceptance criteria.

xSpecification BDD tests are normally unit tests and are unlikely to be acceptable user acceptance criteria.

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