There are many articles on the net about how to use SpecFlow, how to set up TFS to run tests, but there is not one that contains all aspects. In this article, I'll show you how you can make running and editing SpecFlow scripts easy for everyone.
Under the cut you will learn how to get:
- Running tests from TFS
- Automatic linking of scripts to test cases in TFS
- Always up-to-date content of test cases in TFS
- Ability to edit scripts directly in the version control system by testers
prehistory
We were faced with the task of automating application testing using the BDD approach. Since TFS is the basis of the task tracking system in our company, a picture has formed in my head where the steps of the SpecFlow script are the steps of test cases in TFS, and the tests are launched from test plans. More about how I implemented it.
What we need:
- Project with tests on SpecFlow
- Azure DevOps Server (aka Team Foundation Server)
- Tool to synchronize SpecFlow scripts with test cases in TFS
Setting
1. Create a project assembly with tests
Everything is simple here, assembly and publication of artifacts. More on the third task later.
2. Create a release to run tests
Creating a release with one task - Visual Studio Test
In this case, the task is configured to run tests manually from the test plan
3. Synchronization of test cases
We know that Visual Studio allows you to link test methods to test cases in TFS and run them from test plans. In order not to do it manually, and also in order to synchronize the content of the scripts, I wrote a simple console application
How to use FeatureSync
Add namespace and locale to feature file header:
#language:en
@Namespace:Application.Autotests
Feature: Log to application
*namespace must match the name of the .dll file that contains the test methods
Create empty test cases in TFS and add tags with their id to scripts:
@2124573 @posistive
Scenario: Successful authorization
Given I on authorization page
And I enter:
| Login | Password |
| user | pass |
When I press Login button
Then Browser redirect on Home page
Launch FeatureSync:
FeatureSync.exe -f C:FolderWithFeatures -s https://tfs.server.com/collection -t 6ppjfdysk-your-tfs-token-2d7sjwfbj7rzba
In our case, the launch occurs after building the project with tests:
Synchronization result
Synchronized SpecFlow script steps and set Automation status
4. Test plan setup
We create a test plan, add our automated cases to it, select build and release in the settings
5. Run Tests
Select the required test in the test plan and run it.
Conclusion
Advantages of this config:
- any tester can open the fetaure file in the version control web form, edit it and the changes will take effect immediately after the build
- you can run tests at any time individually
- transparent test model - we always know what the test we run does.
Source: habr.com