-
The scanner is throwing the error ''setup' method should have @istest annotation' for a method that is annotated with @testsetup. Thanks for your help! Here's the code: @TestSetup static void setup(){
//switch off triggers
List<TriggerControl__c> triggerControls = new List<TriggerControl__c>();
triggerControls.add(new TriggerControl__c(Name = 'CaseTrigger', Active__c = false));
triggerControls.add(new TriggerControl__c(Name = 'ApplicationTrigger', Active__c = false));
triggerControls.add(new TriggerControl__c(Name = 'DecisionTrigger', Active__c = false));
triggerControls.add(new TriggerControl__c(Name = 'CaseAreaTrigger', Active__c = false));
insert triggerControls;
//insert test data
Contact applicant = new Contact(FirstName = 'Adam', LastName = 'Mialczynski', Email = 'test@test.pl', Contact_Identifier__c = '12345');
Contact applicantTTMR = new Contact(FirstName = 'Andy', LastName = 'Balboa', Email = 'test@test.us', Contact_Identifier__c = '12333');
Contact applicantFT = new Contact(FirstName = 'Fast', LastName = 'Track', Email = 'test@test.pl', Contact_Identifier__c = '12346');
insert new List<Contact>{applicantTTMR,applicant,applicantFT};
List<Application__c> apps = new List<Application__c>();
Application__c app1 = new Application__c(Profession__c = 'Paramedicine',
Reference_Number__c = '12345',
Division__c = 'Division',
CategoryOfApplicant__c = 'Division to Division',
RegistrationType__c = 'General'
);
apps.add(app1);
Application__c app2 = new Application__c(Profession__c = 'Paramedicine',
Reference_Number__c = '23451',
Division__c = 'Radiation Therapist',
CategoryOfApplicant__c = 'Division to Division',
RegistrationType__c = 'Limited'
);
apps.add(app2);
Application__c appFastTrack = new Application__c(Profession__c = 'Paramedicine',
Reference_Number__c = '23451',
Division__c = 'Radiation Therapist',
CategoryOfApplicant__c = 'Fast Track',
RegistrationType__c = 'Limited'
);
Application__c ttmrApp = new Application__c(
Profession__c = 'Paramedicine',
Reference_Number__c = '23451',
NZ_Registration_Number__c = '123456',
CategoryOfApplicant__c = 'Trans Tasman Mutual Recognition',
RegistrationType__c = 'General'
);
apps.add(ttmrApp);
apps.add(appFastTrack);
insert apps;
List<Case> cases = new List<Case>();
RecordType appCaseRecordType = [SELECT Id FROM RecordType WHERE SobjectType = 'Case' AND Name = 'Application'];
System.assertNotEquals(null, appCaseRecordType, 'There should be application record type for cases');
Case case1 = new Case(RecordTypeId = appCaseRecordType.Id, Application__c = app1.Id, ContactId = applicant.Id, Has_Been_Assigned_To_User__c = true);
cases.add(case1);
Case case2 = new Case(RecordTypeId = appCaseRecordType.Id, Application__c = app2.Id, ContactId = applicant.Id, Has_Been_Assigned_To_User__c = true);
cases.add(case2);
Case caseFastTrack = new Case(RecordTypeId = appCaseRecordType.Id, Application__c = appFastTrack.Id, ContactId = applicantFT.Id, Has_Been_Assigned_To_User__c = true);
cases.add(caseFastTrack);
cases.add(new Case(RecordTypeId = appCaseRecordType.Id, Application__c = ttmrApp.Id, ContactId = applicantTTMR.Id, Has_Been_Assigned_To_User__c = true));
insert cases;
RecordType qualRT = [SELECT Name FROM RecordType WHERE SobjectType = 'Case_Area__c' AND Name = :GlobalConstants.CA_QUALIFICATION_RT_NAME LIMIT 1];
System.assertNotEquals(null, qualRT, 'Missing record type for request for extension of time case area.');
RecordType chcRecordType = [SELECT Id FROM RecordType WHERE DeveloperName = :GlobalConstants.CHC_RT_DEV_NAME LIMIT 1];
insert new Case_Area__c(Case__c = case1.Id, RecordTypeId = qualRT.Id, Status__c = GlobalConstants.CA_STATUS_PENDING_EXTERNAL_INFORMATION, Follow_Up_Date__c = Date.today() + 10);
insert new Case_Area__c(Case__c = case1.Id, RecordTypeId = chcRecordType.Id, Status__c = GlobalConstants.CA_STATUS_DONE, Outcome__c = 'Accepted', Complete__c = 'Yes', Classification__c = 'B');
setup2();
}
@Future
static void setup2() {
Group testQueue = new Group(
Name = 'Decisions Test Queue',
Type = 'Queue'
);
insert testQueue;
QueueSobject mappingObject = new QueueSobject(QueueId = testQueue.Id, SobjectType = 'Case');
insert mappingObject;
} |
Beta Was this translation helpful? Give feedback.
Answered by
adangel
May 18, 2021
Replies: 1 comment
-
This is probably a false-positive of the rule ApexUnitTestMethodShouldHaveIsTestAnnotation. That's a similar case like in #3183 which will probably be fixed with the next PMD version. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
adangel
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is probably a false-positive of the rule ApexUnitTestMethodShouldHaveIsTestAnnotation.
The current rule impl looks for Assert statement, which it found it your setup() method - hence it thinks, this must be a test method.
That's a similar case like in #3183 which will probably be fixed with the next PMD version.