-
-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add rule to avoid that TestCase rely on Initialize
this pull request propose a rule to validate that users do not use initialize but setUp. #5792
- Loading branch information
Hely
committed
Apr 23, 2024
1 parent
930ce39
commit 79948e9
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Class { | ||
#name : 'ReUseSetUpRuleTest', | ||
#superclass : 'ReAbstractRuleTestCase', | ||
#category : 'General-Rules-Tests-Migrated', | ||
#package : 'General-Rules-Tests', | ||
#tag : 'Migrated' | ||
} | ||
|
||
{ #category : 'initialization' } | ||
ReUseSetUpRuleTest >> initialize [ | ||
] | ||
|
||
{ #category : 'tests' } | ||
ReUseSetUpRuleTest >> testRule [ | ||
|
||
| critiques | | ||
self class compile: 'initialize'. | ||
critiques := self myCritiquesOnClass: self class. | ||
self assert: critiques size equals: 1. | ||
[ "code of the test" ] ensure: [ (self class >> #initialize) removeFromSystem ] | ||
] | ||
|
||
{ #category : 'tests' } | ||
ReUseSetUpRuleTest >> testRuleNotViolated [ | ||
|
||
| critiques | | ||
self class compile: 'setUp'. | ||
critiques := self myCritiquesOnClass: self class. | ||
self assertEmpty: critiques. | ||
[ "code of the test" ] ensure: [ (self class >> #setUp) removeFromSystem ] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
" | ||
this smell arise when we use initialize instead of setUp in a TestCase | ||
" | ||
Class { | ||
#name : 'ReUseSetUpRule', | ||
#superclass : 'ReAbstractRule', | ||
#category : 'General-Rules-Migrated', | ||
#package : 'General-Rules', | ||
#tag : 'Migrated' | ||
} | ||
|
||
{ #category : 'testing - interest' } | ||
ReUseSetUpRule class >> checksClass [ | ||
^ true | ||
] | ||
|
||
{ #category : 'manifest' } | ||
ReUseSetUpRule class >> uniqueIdentifierName [ | ||
"This number should be unique and should change only when the rule completely change semantics" | ||
|
||
^ 'UseSetUpRule' | ||
] | ||
|
||
{ #category : 'running' } | ||
ReUseSetUpRule >> basicCheck: aClass [ | ||
|
||
aClass isTestCase ifFalse: [ ^ false ]. | ||
^ aClass selectors includes: #initialize | ||
] | ||
|
||
{ #category : 'accessing' } | ||
ReUseSetUpRule >> group [ | ||
|
||
^ 'Design Flaws' | ||
] | ||
|
||
{ #category : 'testing' } | ||
ReUseSetUpRule >> isRewriteRule [ | ||
|
||
^ true | ||
] | ||
|
||
{ #category : 'accessing' } | ||
ReUseSetUpRule >> name [ | ||
|
||
^ 'Uses setUp instead of initialize for Test class.' | ||
] | ||
|
||
{ #category : 'accessing' } | ||
ReUseSetUpRule >> severity [ | ||
|
||
^ #error | ||
] |