Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsheepuk committed Apr 24, 2024
1 parent 145f942 commit 61f500d
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 116 deletions.
120 changes: 85 additions & 35 deletions features/testingt.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ Feature: providing testingT compatibility
As a test suite
I need to be able to provide a testing.T compatible interface

Scenario: should fail test if FailNow called on testing T
Scenario Outline: should fail test with no message if <op> called on testing T
Given a feature "failed.feature" file:
"""
Feature: failed feature
Scenario: fail a scenario
Given passing step
When I fail the test by calling FailNow on testing T
When my step fails the test by calling <op> on testing T
"""
When I run feature suite
Then the suite should have failed
Expand All @@ -20,8 +20,61 @@ Feature: providing testingT compatibility
"""
And the following step should be failed:
"""
I fail the test by calling FailNow on testing T
my step fails the test by calling <op> on testing T
"""
Examples:
| op |
| Fail |
| FailNow |

Scenario Outline: should fail test with message if <op> called on T
Given a feature "failed.feature" file:
"""
Feature: failed feature
Scenario: fail a scenario
Given passing step
When my step fails the test by calling <op> on testing T with message "an unformatted message"
"""
When I run feature suite
Then the suite should have failed
And the following steps should be passed:
"""
passing step
"""
And the following step should be failed:
"""
my step fails the test by calling <op> on testing T with message "an unformatted message"
"""
Examples:
| op |
| Error |
| Fatal |


Scenario Outline: should fail test with formatted message if <op> called on T
Given a feature "failed.feature" file:
"""
Feature: failed feature
Scenario: fail a scenario
Given passing step
When my step fails the test by calling <op> on testing T with message "a formatted message %s" and argument "arg1"
"""
When I run feature suite
Then the suite should have failed
And the following steps should be passed:
"""
passing step
"""
And the following step should be failed:
"""
my step fails the test by calling <op> on testing T with message "a formatted message %s" and argument "arg1"
"""
Examples:
| op |
| Errorf |
| Fatalf |

Scenario: should pass test when testify assertions pass
Given a feature "testify.feature" file:
Expand All @@ -30,16 +83,16 @@ Feature: providing testingT compatibility
Scenario: pass a scenario
Given passing step
When I call testify's assert.Equal with expected "exp" and actual "exp"
When I call testify's require.Equal with expected "exp" and actual "exp"
When my step calls testify's assert.Equal with expected "exp" and actual "exp"
When my step calls testify's require.Equal with expected "exp" and actual "exp"
"""
When I run feature suite
Then the suite should have passed
And the following steps should be passed:
"""
passing step
I call testify's assert.Equal with expected "exp" and actual "exp"
I call testify's require.Equal with expected "exp" and actual "exp"
my step calls testify's assert.Equal with expected "exp" and actual "exp"
my step calls testify's require.Equal with expected "exp" and actual "exp"
"""

Scenario: should fail test when testify assertions do not pass
Expand All @@ -49,8 +102,8 @@ Feature: providing testingT compatibility
Scenario: fail a scenario
Given passing step
When I call testify's assert.Equal with expected "exp" and actual "not"
And I call testify's assert.Equal with expected "exp2" and actual "not"
When my step calls testify's assert.Equal with expected "exp" and actual "not"
And my step calls testify's assert.Equal with expected "exp2" and actual "not"
"""
When I run feature suite
Then the suite should have failed
Expand All @@ -60,11 +113,11 @@ Feature: providing testingT compatibility
"""
And the following steps should be failed:
"""
I call testify's assert.Equal with expected "exp" and actual "not"
my step calls testify's assert.Equal with expected "exp" and actual "not"
"""
And the following steps should be skipped:
"""
I call testify's assert.Equal with expected "exp2" and actual "not"
my step calls testify's assert.Equal with expected "exp2" and actual "not"
"""

Scenario: should fail test when multiple testify assertions are used in a step
Expand All @@ -74,7 +127,7 @@ Feature: providing testingT compatibility
Scenario: fail a scenario
Given passing step
When I call testify's assert.Equal 3 times
When my step calls testify's assert.Equal 3 times
"""
When I run feature suite
Then the suite should have failed
Expand All @@ -84,7 +137,7 @@ Feature: providing testingT compatibility
"""
And the following steps should be failed:
"""
I call testify's assert.Equal 3 times
my step calls testify's assert.Equal 3 times
"""

Scenario: should pass test when multiple testify assertions are used successfully in a step
Expand All @@ -94,24 +147,24 @@ Feature: providing testingT compatibility
Scenario: pass a scenario
Given passing step
When I call testify's assert.Equal 3 times with match
When my step calls testify's assert.Equal 3 times with match
"""
When I run feature suite
Then the suite should have passed
And the following steps should be passed:
"""
passing step
I call testify's assert.Equal 3 times with match
my step calls testify's assert.Equal 3 times with match
"""

Scenario: should skip test when skip is called on the testing.T
Scenario Outline: should skip test when <op> is called on the testing.T
Given a feature "testify.feature" file:
"""
Feature: skipped feature
Scenario: skip a scenario
Given passing step
When I skip the test by calling Skip on testing T
When my step skips the test by calling <op> on testing T
"""
When I run feature suite
Then the suite should have passed
Expand All @@ -121,24 +174,21 @@ Feature: providing testingT compatibility
"""
And the following steps should be skipped:
"""
I skip the test by calling Skip on testing T
my step skips the test by calling <op> on testing T
"""
Examples:
| op |
| Skip |
| SkipNow |

Scenario: should log to testing.T
Given a feature "logging.feature" file:
"""
Feature: logged feature
Scenario: should log when Logf/Log called on testing.T
When my step calls Logf on testing T with message "format this %s" and argument "formatparam1"
And my step calls Log on testing T with message "log this message"
Then the logged messages should include "format this formatparam1"
And the logged messages should include "log this message"

Scenario: logged scenario
Given passing step
When I call Logf on testing T with message "format this %s" and argument "formatparam1"
And I call Log on testing T with message "log this message"
"""
When I run feature suite
Then the suite should have passed
And the following steps should be passed:
"""
passing step
I call Logf on testing T with message "format this %s" and argument "formatparam1"
I call Log on testing T with message "log this message"
"""
Scenario: should log when godog.Logf/Log called
When my step calls godog.Logf with message "format this %s" and argument "formatparam1"
And my step calls godog.Log with message "log this message"
Then the logged messages should include "format this formatparam1"
And the logged messages should include "log this message"
1 change: 1 addition & 0 deletions out.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ok github.com/cucumber/godog 0.948s
14 changes: 8 additions & 6 deletions run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,11 +525,12 @@ func Test_AllFeaturesRun(t *testing.T) {
...................................................................... 210
...................................................................... 280
...................................................................... 350
....................................... 389
...................................................................... 420
... 423
101 scenarios (101 passed)
389 steps (389 passed)
108 scenarios (108 passed)
423 steps (423 passed)
0s
`

Expand All @@ -553,11 +554,12 @@ func Test_AllFeaturesRunAsSubtests(t *testing.T) {
...................................................................... 210
...................................................................... 280
...................................................................... 350
....................................... 389
...................................................................... 420
... 423
101 scenarios (101 passed)
389 steps (389 passed)
108 scenarios (108 passed)
423 steps (423 passed)
0s
`

Expand Down
Loading

0 comments on commit 61f500d

Please sign in to comment.