Skip to content

Commit bf10165

Browse files
authored
Merge pull request #14 from KyleKincer/codex/analyze-subtest-functionality-with-t.run
Prevent stats carryover between subtests
2 parents 65fc0ef + 0131170 commit bf10165

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

testing/Project/Sources/Classes/Testing.4dm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ Function run($name : Text; $subtest : 4D:C1709.Function; $data : Variant) : Bool
4444
var $subT : cs:C1710.Testing
4545
$subT:=cs:C1710.Testing.new()
4646

47-
// Share assertion and statistics objects with parent
48-
$subT.assert:=This:C1470.assert
49-
$subT.stats:=This:C1470.stats
50-
$subT.classInstance:=This:C1470.classInstance
47+
// Share assertion object with parent but keep stats isolated
48+
$subT.assert:=This:C1470.assert
49+
$subT.classInstance:=This:C1470.classInstance
5150

5251
var $result : Boolean
5352
$result:=True:C214

testing/Project/Sources/Classes/_TestingTest.4dm

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,22 @@ Function test_run_with_data_argument($t : cs:C1710.Testing)
172172
$t.assert.areEqual($t; "bad: 3"; $testing.logMessages[1]; "Should prefix log with case name")
173173
$t.assert.isTrue($t; $testing.failed; "Parent should fail if any case fails")
174174

175+
Function test_run_subtest_stats_isolated($t : cs:C1710.Testing)
176+
177+
var $testing : cs:C1710.Testing
178+
$testing:=cs:C1710.Testing.new()
179+
180+
// First subtest records a stat
181+
$testing.run("first"; Formula($1.stats.mock("mocked"; []; Null)))
182+
183+
// Second subtest should start with fresh stats
184+
$testing.run("second"; Formula($1.assert.areEqual($1; 0; $1.stats.getStat("mocked").getNumberOfCalls(); "Stats should not carry over between subtests")))
185+
186+
// Parent stats should remain unaffected
187+
var $parentStat : cs:C1710._UnitStatsDetail
188+
$parentStat:=$testing.stats.getStat("mocked")
189+
$t.assert.areEqual($t; 0; $parentStat.getNumberOfCalls(); "Parent stats should remain unaffected")
190+
175191
Function _addOneCase($t : cs:C1710.Testing; $case : Object)
176192

177193
var $got : Integer

0 commit comments

Comments
 (0)