Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow analysis to continue even after the first test error #56

Merged
merged 7 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .smalltalk.ston
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ SmalltalkCISpec {
#testing : {
#coverage : {
#packages : [ 'MuTalk*' ]
},
#exclude : {
#classes : [ #AuxiliarTestClassForContinuingTestsExecutionAfterFirstFail ]
}
}
}
17 changes: 17 additions & 0 deletions src/MuTalk-Model/MethodMutation.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ MethodMutation >> runMutant [
] ensure: [ self uninstall ]
]

{ #category : 'running' }
MethodMutation >> runMutantWithoutStoppingOnError [

^ [
self install.
self runTestsWithoutStoppingOnError
] ensure: [ self uninstall ]
]

guillep marked this conversation as resolved.
Show resolved Hide resolved
{ #category : 'private' }
MethodMutation >> runTests [

Expand All @@ -145,6 +154,14 @@ MethodMutation >> runTests [
runStoppingOnFirstFailOrError
]

{ #category : 'private' }
MethodMutation >> runTestsWithoutStoppingOnError [

^ (TestSuite named: 'Tests cases for: ' , self printString)
addTests: testCaseReferences;
run
]
guillep marked this conversation as resolved.
Show resolved Hide resolved

{ #category : 'private' }
MethodMutation >> testCaseReferences [
^ testCaseReferences
Expand Down
15 changes: 15 additions & 0 deletions src/MuTalk-Model/MutantEvaluation.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,18 @@ MutantEvaluation >> value [
results: testResults
producedBy: self
]

{ #category : 'evaluation' }
MutantEvaluation >> valueWithoutStoppingOnError [

| testResults |
self initializeCoverageResultIfNil.

mutation testCaseReferences:
(strategy testCasesToEvaluate: mutation for: self).
testResults := mutation runMutantWithoutStoppingOnError.
^ MutantEvaluationResult
for: mutation
results: testResults
producedBy: self
]
guillep marked this conversation as resolved.
Show resolved Hide resolved
37 changes: 28 additions & 9 deletions src/MuTalk-Model/MutationTestingAnalysis.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Class {
'logger',
'budget',
'mutationsSelectionStrategy',
'mutantResults'
'mutantResults',
'stopOnErrorOrFail'
],
#category : 'MuTalk-Model',
#package : 'MuTalk-Model'
Expand Down Expand Up @@ -346,6 +347,12 @@ MutationTestingAnalysis >> coverageAnalysisResult: anObject [
coverageAnalysisResult := anObject
]

{ #category : 'accessing' }
MutationTestingAnalysis >> doNotStopOnErrorOrFail [

stopOnErrorOrFail := false
]

{ #category : 'results' }
MutationTestingAnalysis >> generalResult [
^ MutationTestingGeneralResult
Expand All @@ -370,16 +377,21 @@ MutationTestingAnalysis >> generateMutations [
{ #category : 'running' }
MutationTestingAnalysis >> generateResults [

| mutantEvaluation |
mutantResults := OrderedCollection new.
mutations do: [ :aMutation |
(budget exceedsBudgetOn: mutantResults fromTotalMutations: mutations) ifTrue: [
^ mutantResults ].
(budget exceedsBudgetOn: mutantResults fromTotalMutations: mutations)
ifTrue: [ ^ mutantResults ].
logger logStartEvaluating: aMutation.
mutantResults add: (MutantEvaluation
for: aMutation
using: testCases
following: mutantsEvaluationStrategy
andConsidering: self coverageAnalysisResult) value ].
mutantEvaluation := MutantEvaluation
for: aMutation
using: testCases
following: mutantsEvaluationStrategy
andConsidering: self coverageAnalysisResult.

mutantResults add: (stopOnErrorOrFail
ifTrue: [ mutantEvaluation value ]
ifFalse: [ mutantEvaluation valueWithoutStoppingOnError ]) ].
^ mutantResults
]

Expand All @@ -402,7 +414,8 @@ MutationTestingAnalysis >> initializeFor: someTestCasesReferences mutating: some
mutantResults := OrderedCollection new.
elapsedTime := 0.
logger := aLogger.
budget := aBudget
budget := aBudget.
stopOnErrorOrFail := true
]

{ #category : 'accesing' }
Expand Down Expand Up @@ -478,6 +491,12 @@ MutationTestingAnalysis >> run [
ex return: false]
]

{ #category : 'accessing' }
MutationTestingAnalysis >> stopOnErrorOrFail: aBoolean [

stopOnErrorOrFail := aBoolean
]

{ #category : 'accesing' }
MutationTestingAnalysis >> testBaseClasses [

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Class {
#name : 'AuxiliarTestClassForContinuingTestsExecutionAfterFirstFail',
#superclass : 'TestCase',
#classInstVars : [
'counter'
],
#category : 'MuTalk-TestResources',
#package : 'MuTalk-TestResources'
}

{ #category : 'accessing' }
AuxiliarTestClassForContinuingTestsExecutionAfterFirstFail class >> counter [

^ counter
]

{ #category : 'accessing' }
AuxiliarTestClassForContinuingTestsExecutionAfterFirstFail class >> counter: anObject [

counter := anObject
]

{ #category : 'accessing' }
AuxiliarTestClassForContinuingTestsExecutionAfterFirstFail class >> increment [

counter := counter + 1
]

{ #category : 'accessing' }
AuxiliarTestClassForContinuingTestsExecutionAfterFirstFail class >> reset [

counter := 0
]

{ #category : 'tests' }
AuxiliarTestClassForContinuingTestsExecutionAfterFirstFail >> testA [

self class increment.
self assert: self class counter < 4
]

{ #category : 'tests' }
AuxiliarTestClassForContinuingTestsExecutionAfterFirstFail >> testB [

self class increment.
self assert: self class counter < 4
]

{ #category : 'tests' }
AuxiliarTestClassForContinuingTestsExecutionAfterFirstFail >> testC [

self class increment.
self assert: self class counter < 4
]
19 changes: 19 additions & 0 deletions src/MuTalk-Tests/MutationTestingAnalysisTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,22 @@ MutationTestingAnalysisTest >> testExecutingTwoMutations [
results do: [ :mutationResult | self assert: mutationResult killed ].
self assert: generalResult numberOfKilledMutants = 2
]

{ #category : 'tests' }
MutationTestingAnalysisTest >> testRunningAllTests [
"This test verify that the test evaluation keeps running even after the first error, if specified"

| analysis |
analysis := MutationTestingAnalysis
testCasesFrom: { AuxiliarTestClassForContinuingTestsExecutionAfterFirstFail }
mutating: { AuxiliarClassForMutationTestingAnalysis }
using: MutantOperator contents.

analysis doNotStopOnErrorOrFail.
"In this class, tests fail after a certain of executions"
AuxiliarTestClassForContinuingTestsExecutionAfterFirstFail reset.
analysis run.
"Counting the number of failed test for a mutant"
self assert:
analysis generalResult killedMutants first result failures size > 1
]
3 changes: 2 additions & 1 deletion src/MuTalk-Tests/TestCasesSelectionStrategyTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ TestCasesSelectionStrategyTest >> allTestsFromPackage [
with: TestClassForTestingCoverage
with: AuxiliarTestClassForTestingStrategies
with: AuxiliarClassForMutationTestingAnalysisTest
with: AuxiliarTestClassForMTBudget)
with: AuxiliarTestClassForMTBudget
with: AuxiliarTestClassForContinuingTestsExecutionAfterFirstFail)
inject: OrderedCollection new
into: [:tests :testClass |
tests addAll: testClass suite tests.
Expand Down
Loading