Skip to content

Commit

Permalink
Update testIdentifier function to include test path
Browse files Browse the repository at this point in the history
  • Loading branch information
nprizal committed Jan 15, 2025
1 parent 6cfe02f commit 9ca7b49
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
4 changes: 2 additions & 2 deletions internal/runner/run_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewRunResult(mutedTests []plan.TestCase) *RunResult {
}

for _, testCase := range mutedTests {
identifier := testIdentifier(testCase)
identifier := mutedTestIdentifier(testCase)
r.mutedTestLookup[identifier] = true
}
return r
Expand Down Expand Up @@ -67,7 +67,7 @@ func (r *RunResult) RecordTestResult(testCase plan.TestCase, status TestStatus)
test := r.getTest(testCase)
test.Status = status
test.ExecutionCount++
if r.mutedTestLookup[testIdentifier(testCase)] {
if r.mutedTestLookup[mutedTestIdentifier(testCase)] {
test.Muted = true
}
}
Expand Down
13 changes: 7 additions & 6 deletions internal/runner/run_result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,22 @@ func TestMutedTests(t *testing.T) {
func TestRunStatistics(t *testing.T) {
r := NewRunResult([]plan.TestCase{
// muted tests
{Scope: "mango", Name: "is sweet"},
{Scope: "mango", Name: "is sweet", Path: "mango.rb:1"},
{Scope: "mango", Name: "is sour"},
{Scope: "cat", Name: "is not a fruit"}, // unrecorded (not related to this run) test case should be ignored
})

// passed on first run: 2
// passed on first run: 3
r.RecordTestResult(plan.TestCase{Scope: "apple", Name: "is red"}, TestStatusPassed)
r.RecordTestResult(plan.TestCase{Scope: "mango", Name: "is red"}, TestStatusPassed)
r.RecordTestResult(plan.TestCase{Scope: "mango", Name: "is red", Path: "mango.rb:3"}, TestStatusPassed)
r.RecordTestResult(plan.TestCase{Scope: "mango", Name: "is red", Path: "mango.rb:7"}, TestStatusPassed) // Different tests with the same name and scope should be counted separately

//passed on retry: 1
r.RecordTestResult(plan.TestCase{Scope: "apple", Name: "is green"}, TestStatusFailed)
r.RecordTestResult(plan.TestCase{Scope: "apple", Name: "is green"}, TestStatusPassed)

// muted: 1 failed, 1 passed
r.RecordTestResult(plan.TestCase{Scope: "mango", Name: "is sweet"}, TestStatusPassed)
r.RecordTestResult(plan.TestCase{Scope: "mango", Name: "is sweet", Path: "mango.rb:5"}, TestStatusPassed) // This test matched with a test in the muted tests lists even though the path is different because we only compare the scope and name for muted tests
r.RecordTestResult(plan.TestCase{Scope: "mango", Name: "is sour"}, TestStatusFailed)

// failed: 1
Expand All @@ -199,8 +200,8 @@ func TestRunStatistics(t *testing.T) {
stats := r.Statistics()

if diff := cmp.Diff(stats, RunStatistics{
Total: 7,
PassedOnFirstRun: 2,
Total: 8,
PassedOnFirstRun: 3,
PassedOnRetry: 1,
MutedPassed: 1,
MutedFailed: 1,
Expand Down
10 changes: 10 additions & 0 deletions internal/runner/test_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ type TestResult struct {
Muted bool
}

// testIdentifier returns a unique identifier for a test case based on its scope, name and path.
// Different tests can have the same name and scope, therefore the path is included in the identifier
// to make it unique.
func testIdentifier(testCase plan.TestCase) string {
return testCase.Scope + "/" + testCase.Name + "/" + testCase.Path
}

// mutedTestIdentifier returns a unique identifier for a muted test case based on its scope and name.
// Test Engine server identify a unique tests by its scope and name only, therefore we need follow the same logic
// to match a local test with the list of muted tests received from the server.
func mutedTestIdentifier(testCase plan.TestCase) string {
return testCase.Scope + "/" + testCase.Name
}

0 comments on commit 9ca7b49

Please sign in to comment.