Reputation: 688
I wrote this gherkin feature and it works perfectly. But my company asked me to be able to run it several times during the tests. We have a client side of the application that control the server side to simulate a real person using the software. So my client side is instantiated once and must run 3 times this scenario.
Is there a "for" statement like I can use here?
Feature: Test program startup time
Background:
Given my program is activated with a licence
Scenario: Startup
Given I want to use a clean installation
Given the user preferences file is user_startup_performances.config
Given the CurrentPath directory is empty
Given I want to monitor startup performances
Then I want to log those data
Cheers !
Upvotes: 4
Views: 7542
Reputation: 20230
In your current feature you write:
Given I want to monitor start-up performances for run '<id>'
As you are using "I want" after the "Given" you should instead be using a "Then" because you are expecting an outcome.
Also the following:
Then I want to log those data
is pretty much the same as the previous Given i.e. you want to obtain log data.
I'd re-write your scenario as:
Feature: Test my program startup time
Background:
Given the system is activated with a license
And I have a clean installation environment
Scenario Outline: Startup
Given the system is ready to start
When I perform test run '<id>'
Then the system should start in less than 3 seconds
And the system should generate log data for test run '<id>'
Examples: Run ID
| id |
| 1 |
| 2 |
| 3 |
Also if the step:
And I have a clean installation environment
explicitly clears the CurrentPath and sets the config file as user_startup_performances.config, then I'd get rid of:
And the user preferences file is user_startup_performances.config
And the CurrentPath directory is empty
Which is what I've done in my suggested re-write.
Upvotes: 2
Reputation: 688
You're right, that's not just a test, it's one of the performance tests we run every night to see the stability of the solution. So the point is more to get data than to to see the green success button :)
If specflow is not the best solution, which tool can be better?
The design of the software do not allow me to use "When I run the program 3 times" unfortunately... and i didn't wanted to just repeat the same line 3 times.
Anyway, i used a scenario outline and defined my steps to be dependent on the Examples. Then, if someone want to change the number of run, all he have to do is to add more lines in the example.
I was looking for a loop statement as i'm a beginner with those technologies. It was also not the best tasks for a first scenario :)
Thanks !!
PS : here is the scenario
Feature: Test my program startup time
Background:
Given my program is activated with a licence elite
Scenario Outline: Startup
Given I want to use a clean installation
Given the user preferences file is user_startup_performances.config
Given the CurrentPath directory is empty
Given I want to monitor startup performances for run '<id>'
Then I want to log those data
Examples: Run ID
| id |
| 1 |
| 2 |
| 3 |
Upvotes: 0
Reputation: 6961
I'm not sure that this is a "test".
It's definitely a script that captures data, but tests also have a condition in them, a value or state that has to be verified.
So I would expect to see something more like
Given I set something up
And I setup something else
....
When I run the program
Then my startup time should be less than 1 second
However, I do understand your desire for a simple consistent way to run this test, and while I think that SpecFlow might not be the best means of achieving what you want, you might want to consider your tests granularity. For example you could rewrite your scenario as
Given I ...
When I run the program
Then my startup time should be less than 1 second
When I run the program
Then my startup time should be less than 1 second
When I run the program
Then my startup time should be less than 1 second
And now you have it tested three times.
Or you could write it as
Given I ...
When I run the program 3 times
Then my startup time should be less than 1 second
and then in your C#
[When("I run the program (\d+) times")]
public void WhenIRunTheProgramManyTimes(int count)
{
for(int i=0; i++; i<count)
WhenIRunTheProgram();
}
[When("I run the program")]
public void WhenIRunTheProgram()
{
....
Also have a look at Dan North's Whose Domain is it anyway?, it might help you structure your future scenarios. :-)
Upvotes: 2