Reputation: 1199
The goal: I want to know how many test do I have during running my test suite.
I'm trying to get overall number of test scenarios written in BDD style and print that number in console. All test files are in ./features directory. There are subdirectories (so I need to search recursively) Some of tests are commented (using #)
Simple scenario looks like that:
Scenario: blah-blah-blah
Given blah
When blah bloh
Then bluh bluh
That's pretty simple and works as a charm:
grep -r "^\s*Scenario:" ./features/ | wc -l
The tricky part is there could be tests which have "Scenario Outline" keyword. On the bottom of test there's a table with examples. Scenario may look like that:
Scenario Outline: blah
Given blah <score>
When bloh <performance>
Then blah-bloh-bluh <completion>
Examples:
| score | performance | completion |
| 4/4 | 100 | 50 |
| 3/4 | 75 | 50 |
| 4/4 | 100 | 5 |
On the first line we've got headers - we shouldn't count them. So, in this case we have 3 tests. So far I've done something like that:
find ./features -type f -exec sed -n -e '/Scenario Outline/,/Scenario/ p' {} + | grep \| | wc -l
Unfortunately there are two issues I couldn't figure out:
Thanks for every advice!
Upvotes: 0
Views: 61
Reputation: 26
I'm not sure if pipes can occur anywhere else in the files, but if not the following command will count all lines starting with Scenario and all tables rows while skipping the first row.
find ./features -type f -print0 | \
xargs -0 awk '/^\s*Scenario:/; /\|/ { if (intable) print; intable=1 } intable && $0 !~ /\|/ { intable=0 }' | \
wc -l
Upvotes: 1