Setup and Use SpecFlow BDD with DevExpress XAF
Posted
by Patrick Liekhus
on Geeks with Blogs
See other posts from Geeks with Blogs
or by Patrick Liekhus
Published on Sun, 13 Nov 2011 14:22:51 GMT
Indexed on
2011/11/13
17:52 UTC
Read the original article
Hit count: 623
Let’s get started with using the SpecFlow BDD syntax for writing tests with the DevExpress XAF EasyTest scripting syntax. In order for this to work you will need to download and install the prerequisites listed below. Once they are installed follow the steps outlined below and enjoy.
Prerequisites
Install the following items:
- DevExpress eXpress Application Framework (XAF) found here
- SpecFlow found here
- Liekhus BDD/XAF Testing library found here
Assumptions
I am going to assume at this point that you have created your XAF application and have your Module, Win.Module and Win ready for usage. You should have also set any attributes and/or settings as you see fit.
Setup
So where to start. Create a new testing project within your solution. I typically call this with a similar naming convention as used by XAF, my project name .FunctionalTests (i.e. AlbumManager.FunctionalTests).
Add the following references to your project. It should look like the reference list below.
- DevExpress.Data.v11.x
- DevExpress.Persistent.Base.v11.x
- DevExpress.Persistent.BaseImpl.v11.x
- DevExpress.Xpo.v11.2
- Liekhus.Testing.BDD.Core
- Liekhus.Testing.BDD.DevExpress
- TechTalk.SpecFlow
- TestExecutor.v11.x (found in %Program Files%\DevExpress 2011.x\eXpressApp Framework\Tools\EasyTest
Right click the TestExecutor reference and set the “Copy Local” setting to True. This forces the TestExecutor executable to be available in the bin directory which is where the EasyTest script will be executed further down in the process.
Add an Application Configuration File (app.config) to your test application. You will need to make a few modifications to have SpecFlow generate Microsoft style unit tests. First add the section handler for SpecFlow and then set your choice of testing framework. I prefer MS Tests for my projects.
Add the EasyTest configuration file to your project. Add a new XML file and call it Config.xml.
Open the properties window for the Config.xml file and set the “Copy to Ouput Directory” to “Copy Always”.
You will setup the Config file according to the specifications of the EasyTest library my mapping to your executable and other settings. You can find the details for the configuration of EasyTest here. My file looks like this
Create a new folder in your test project called “StepDefinitions”. Add a new SpecFlow Step Definition file item under the StepDefinitions folder. I typically call this class StepDefinition.cs.
Have your step definition inherit from the Liekhus.Testing.BDD.DevExpress.StepDefinition class. This will give you the default behaviors for your test in the next section.
OK. Now that we have done this series of steps, we will work on simplifying this. This is an early preview of this new project and is not fully ready for consumption. If you would like to experiment with it, please feel free. Our goals are to make this a installable project on it’s own with it’s own project templates and default settings. This will be coming in later versions. Currently this project is in Alpha release.
Let’s write our first test
Remove the basic test that is created for you. We will not use the default test but rather create our own SpecFlow “Feature” files. Add a new item to your project and select the SpecFlow Feature file under C#. Name your feature file as you do your class files after the test they are performing.
Writing a feature file uses the Cucumber syntax of Given… When… Then. Think of it in these terms. Givens are the pre-conditions for the test. The Whens are the actual steps for the test being performed. The Thens are the verification steps that confirm your test either passed or failed. All of these steps are generated into a an EasyTest format and executed against your XAF project. You can find more on the Cucumber syntax by using the Secret Ninja Cucumber Scrolls. This document has several good styles of tests, plus you can get your fill of Chuck Norris vs Ninjas. Pretty humorous document but full of great content.
My first test is going to test the entry of a new Album into the application and is outlined below.
The Feature section at the top is more for your documentation purposes. Try to be descriptive of the test so that it makes sense to the next person behind you. The Scenario outline is described in the Ninja Scrolls, but think of it as test template. You can write one test outline and have multiple datasets (Scenarios) executed against that test. Here are the steps of my test and their descriptions
Given I am starting a new test – tells our test to create a new EasyTest file
And (Given) the application is open – tells EasyTest to open our application defined in the Config.xml
When I am at the “Albums” screen – tells XAF to navigate to the Albums list view
And (When) I click the “New:Album” button – tells XAF to click the New Album button on the ribbon
And (When) I enter the following information – tells XAF to find the field on the screen and put the value in that field
And (When) I click the “Save and Close” button – tells XAF to click the “Save and Close” button on the detail window
Then I verify results as “user” – tells the testing framework to execute the EasyTest as your configured user
Once you compile and prepare your tests you should see the following in your Test View. For each of your CreateNewAlbum lines in your scenarios, you will see a new test ready to execute.
From here you will use your testing framework of choice to execute the test. This in turn will execute the EasyTest framework to call back into your XAF application and test your business application.
Again, please remember that this is an early preview and we are still working out the details. Please let us know if you have any comments/questions/concerns.
Thanks and happy testing.
© Geeks with Blogs or respective owner