Confusion about functional testing, BDD and TDD
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 cla开发者_开发问答ss 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?
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).
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?
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.
精彩评论