> I thought that the BDD process could replace the TDD part, but now, I
> see them as complementary.
Yes, IMHO BDD can be used to extend TDD as well as ATDD.
> About the UI part, I read somewhere that validating UI can only be
> done by a human, and it makes sense.
I agree. Some things you cannot validate by automated tests, like
usability feedback. It is also hard to write automated tests to
validate usability requirements - at least I have not seen this in
practice. Some projects automatically generate screenshots, which are
later validated by a human.
Anyway, the main purpose I see for automated acceptance tests with
Specflow is to automatically confirm acceptance criteria of a feature
(user story). Either including the UI, or some level below (not
testing defined acceptance criteria for the UI). Note that these kind
of tests are usually strictly structured after the Triple-A principle:
Arrange - Act - Assert. "Arrange" sets up all necessary state in the
app (and mocks of excluded systems), "Act" performs the isolated test
on the specific acceptance criteria to be validated, and "Assert"
performs all kinds of assertions for validating the "Act" was
successful. In "Arrange" and "Assert" you do short cuts, like setting
application state through the system API (e.g. setting login state
instead of automating login through the UI) or querying database state
for an assert (instead of navigating to a UI where you would see the
results). The "Act", however, should be isolated for the acceptance
criteria to cover and go through the number of layers you agreed to
test in your acceptance tests. Shortcuts in "Arrange" and "Assert" and
strict isolation of the "Act" for a single acceptance criteria
improves maintainability of the tests and can help with performance.
This is much in contrast to other kinds of UI automation tests, where
previous "Acts" are the "Arrange" for later "Acts" - so you have
basically a series of "Arrange" - "Act" - "Assert" - "Act" - "Assert"
- "Act"..... to test a whole user workflow through the application.
Having covered all your acceptance criteria with isolated SpecFlow
tests does not fully replace this kind of workflow testing. In
addition to doing automated SpecFlow acceptance tests, we suggest to
define typical user workflows through the application, which can be
also used to demo to the user (e.g. in the sprint review) or to
collect usability feedbacks. Having automated acceptance tests,
however, significanlty reduces the number of required workflow tests.
Whether you automate those workflow tests as well is another decision,
they are definitely more brittle to maintain and you always want to
assert them against a human user anyway :-).
> Anyway, I'll be glad to see how you added some Selenium into Specflow.
Integration with automated test runnners like Selenium, Webrat (or
others) works the same like in Cucumber.
> A last point of concern for me is the lack of documentation about
> SpecFlow.
> There are only a few set of examples, so I can prepare a smalll
> presentation, but I don't see how we could build large sets of BDD.
We strive to be fully compatible with Cucumber (on the Gherkin level)
- which means you can apply knowledge of the concept in both worlds
and you can also use examples and documentation of both worlds. There
is plenty if documentation for Cucumber, and it might be one of the
most interesting areas to discuss for us with the Cucumber team, how
we can share/extend their efforts in documentation and examples.
> - how can we separate the scenarios ? In TDD, I can use a Setup for
> every scenario, are all the setups placed in the
> SpecFlowStepDefinition ?
Setups, which I described previously as "Arrange" should be put in
"Given" parts. For every setup you require, you should write another
given fragment. You can chain up multiple givens with "and", and you
can also reuse given fragments in different scenarios.
Same is true for the "Act" which corresponds to "When" in Gherkin.
And the "Assert" corresponds to "Then".
What basically happens is that you build up a DSL for your project,
which can be used to express behavioural expectations against the
system (in terms of Arrange, Act and Assert).
Another interesting aspect is, that with this DSL, the testers can use
the Arrange and Assert parts also for manual testing, to setup initial
state in the system or Assert for things that are not visible on the
UI during the manual test. The DSL is basically also a "testing
interface" to the system.
> - what's the use of @mytag ?
As you figured out already, you can tag scenarios for all kinds of
stuff. We generate unit test categories out of it (so you can
selectively run certain scenarios in your automated build) and you can
also filter for specifically tagged scenarios in extension events.
> - what is a SpecFlowEventDefinition ?
The events are used to extend step definitions - in Cucumber these are
called "Hooks". It allows to extend step definitions or whole
scenarios for (groups of scenarios) with specific cross-cutting
aspects. Like starting a new selenium session for scenarios which are
marked with @seleniumtag.
> BTW, I very much liked the why/how pyramid from Gaspar's document (I
> shamelessly used it for presenting BDD to our product managers ;-)).
Thanks, Gaspar liked it also and shamelessly used it from one of my
talks about Requirements Management :-).
Greetings,
Christian