Database Transaction

193 views
Skip to first unread message

Sörnt

unread,
Nov 13, 2010, 3:45:18 PM11/13/10
to SpecFlow
Hi there,

I am new to SpecFlow so my question may be silly, but I didn't found a
hint for my problem.

In my older NUnits Tests I used the DataRollback attribute Extension
from TeamAgile
(http://www.kyleheon.com/articles/2009/08/21/teamagiles-datarollback-
attribute-upgraded-to-vs-2008-net-3-5-and-nunit-2-5)
to span a database transaction around a test.

Is something like that also possible to archive with SpecFlow?
Basically I want to span a transaction around a Scenario.

Kind regards,
Sörnt

Jonas Bandi

unread,
Nov 13, 2010, 3:52:40 PM11/13/10
to spec...@googlegroups.com
Specflow itself does not provide support for this.
You have to implement it yourself.

You can use SpecFlow hooks for this (i.e: [BeforeScenario], [AfterScenario])

Also have a look at the Transaction Rollback Teardown pattern itself:
http://xunitpatterns.com/Transaction%20Rollback%20Teardown.html

I have better experience with starting with a clean database for each scenario.
Then setting up the database in Before-Hooks and in the Background.

--
mail: jonas...@gmail.com
web: www.jonasbandi.net
blog: blog.jonasbandi.net
twitter: twitter.com/jbandi

Gáspár Nagy

unread,
Nov 13, 2010, 4:02:22 PM11/13/10
to SpecFlow
Hi,

For the first look, it seems that you need to do a specialized
generator by deriving from the build-in xunit generator (https://
github.com/techtalk/SpecFlow/blob/master/Generator/UnitTestProvider/
XUnitTestGeneratorProvider.cs). The specialized generator could add
these attributes if a certain tag ("@rollback") was used in a
scenario.

To use the specialized generator, you have to configure it in
app.config:

<specflow>
<unitTestProvider name="xUnit"
generatorProvider="your_specialized_generator_class, yourassembly" />
...
</specflow>

Br,
Gaspar

Sörnt

unread,
Nov 13, 2010, 5:34:23 PM11/13/10
to SpecFlow
These hooks looks exactly for what I was looking - Thank you very
much!

Best regards,
Sörnt
> mail: jonas.ba...@gmail.com
Reply all
Reply to author
Forward
0 new messages