关于功能测试、BDD 和 TDD 的困惑

发布于 2024-11-03 08:57:00 字数 583 浏览 3 评论 0原文

我有一张表格,其中必须填写多个字段。但是,只有一个字段是必填的。所以,我提出了以下规范:

 [Subject(typeof(CompanyHomeController))]
public class when_the_save_button_is_clicked
{
    private It should_verify_that_the_company_name_has_been_filled;

    private It should_show_some_text_next_to_the_company_field_if_it_has_not_been_filled;

    private It should_submit_all_the_details_on_the_form_if_there_are_no_errors;

    private It should_take_the_user_back_to_the_list_of_companies;
}

现在我想实现这个,但我很困惑,因为它听起来非常像功能测试,我必须使用 mvccontrib.watin dll 之类的东西。我说得对吗,这确实是功能测试?我是否为 BDD 制定了“错误”的规范?

I have a form where several fields have to be filled in. However, only one field is compulsory. So, I came up with the following spec:

 [Subject(typeof(CompanyHomeController))]
public class when_the_save_button_is_clicked
{
    private It should_verify_that_the_company_name_has_been_filled;

    private It should_show_some_text_next_to_the_company_field_if_it_has_not_been_filled;

    private It should_submit_all_the_details_on_the_form_if_there_are_no_errors;

    private It should_take_the_user_back_to_the_list_of_companies;
}

Now I'd like to implement this but I'm getting confused because it sounds very much like functional testing where I'd have to use something like the mvccontrib.watin dlls. Am I right that it's indeed functional testing? Have I formulated the specs "wrong" for BDD?

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

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

发布评论

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

评论(3

待天淡蓝洁白时 2024-11-10 08:57:00

我还不太担心这些定义 - 各种形式的测试和测试之间存在很多模糊的界限。无论如何,BDD。

WRT Watin,我猜你是在谈论通过浏览器进行测试?您可以通过浏览器进行测试或直接在控制器上进行“皮下”测试,这两种方法都是执行 BDD 的有效方法。这种选择更多地取决于您要测试的内容、您希望测试运行的速度等等。

就您的规格而言,我可以看到它们实施起来可能有点棘手。您可能希望对有效/无效提交有不同的规范,例如:(

[Subject(typeof(CompanyHomeController))]
public class company_form_submitted_with_fields_completed
{
    It should_save_all_the_details_to_the_main_list;

    It should_take_the_user_back_to_the_company_list_page;
}

[Subject(typeof(CompanyHomeController))]
public class company_form_submitted_with_some_fields_missing
{
    It should_remain_on_the_company_edit_page;

    It should_warn_that_the_company_field_is_required;
}

请注意,您不需要“私有”修饰符,这会稍微清理一下)。

I wouldn't worry too much about the definitions just yet - there are a lot of blurred boundaries between the various forms of testing & BDD anyway.

WRT Watin, I guess you're talking about testing via the browser? You can test via the browser or 'subcutaneously' directly on your controllers, both are valid ways of doing BDD. That choice is more down to what you're trying to test, how fast you want your tests to run, and so on.

In terms of your specs, I can see they might be a little tricky to implement. You probably want to have different specs for valid/invalid submissions, e.g.:

[Subject(typeof(CompanyHomeController))]
public class company_form_submitted_with_fields_completed
{
    It should_save_all_the_details_to_the_main_list;

    It should_take_the_user_back_to_the_company_list_page;
}

[Subject(typeof(CompanyHomeController))]
public class company_form_submitted_with_some_fields_missing
{
    It should_remain_on_the_company_edit_page;

    It should_warn_that_the_company_field_is_required;
}

(notice you don't need the 'private' modifiers, which cleans it up a bit).

月下客 2024-11-10 08:57:00

将 BDD 视为“示例规范”而不是“功能测试”。

但请记住,BDD 的目标是就应该做什么达成一致,并以示例的形式记录它,这些示例也可以作为测试运行来指导开发人员。

BDD 不是一种系统验证技术,而是一种系统规范技术。它很有用,但对于有趣的算法来说,它本身可能还不够。

因为它是“通过例子”,所以你要说明你会做什么,以及它会如何反应。也许您填写了一份表格,然后将“公司”字段留空。应该如何反应呢?现在也许您填写该一项,但空白另一项。它应该如何做出不同的反应?

因为它是“通过示例进行说明”,所以它确实需要您讲述一系列小故事。

有帮助吗?

Think of BDD as "specification by example" not "functional test."

But remember that the goal of BDD is to reach alignment on what should be done and to document it in the form of examples which will also be runnable as tests to guide the developers.

BDD is not a systems validation technique, but a system specification technique. It's useful, but may be insufficient on its own in the case of interesting algorithms.

Since it's "by example" you state what you would do, and how it would react. Maybe you fill in a form, then blank the Company field. How should it react? Now maybe you fill in that one, but blank another. How should it react differently?

Because it's 'specification by example' it really needs you to tell a series of small stories.

Is that helpful?

若言繁花未落 2024-11-10 08:57:00

经过一些研究,

这澄清了我的很多误解,http://www.msteched .com/2010/NorthAmerica/DPR302。希望它可以帮助那里的人。此外,Amir 的回答 什么是最成熟的 BDD 框架.NET?帮助我更清楚地看到事情。

After doing some research,

This clarified a lot of the misunderstandings I had, http://www.msteched.com/2010/NorthAmerica/DPR302. Hopefully it can help someone out there. Moreover, the answer by Amir What is the most mature BDD Framework for .NET? helped me see things clearer.

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