I'm Kinda newbie in APEX and Testing classes in general.
If I have this type of classes, which basicly about querying and retrieving data from database using SOQL statments:
public class classToTest{
Public List<Account> attrNum1{get;set;}
Public List<Opportunity> attrNum2{get;set;}
public classToTest(){
attrNum1 = [SELECT Id, Name FROM Account WHERE .... ];
attrNum2 = [SELECT Id FROM Opportunity WHERE .... ];
}
}
Is it right and acceptable if the test class is like this:
public class testingClass{
static testMethod void testingClass(){
Test.startTest();
classToTest instanceNum1 = new classToTest();
Test.stopTest();
Set<Id> expectedRecordIds_attrNum1 = new Map<Id, SObject>([SELECT Id, Name FROM Account WHERE .... ]);
Set<Id> actualIds_attrNum1 = new Map<Id, SObject>(instanceNum1.attrNum1);
system.assertEquals(expectedRecordIds_attrNum1, actualIds_attrNum1);
Set<Id> expectedRecordIds_attrNum2 = new Map<Id, SObject>([SELECT Id, Name FROM Account WHERE .... ]);
Set<Id> actualIds_attrNum2 = new Map<Id, SObject>(instanceNum1.attrNum1);
system.assertEquals(expectedRecordIds_attrNum2, actualIds_attrNum2);
}
}
Or I have to insert record with the specific criteria of the SOQL statment in the classToTest
and try to compare it with new instance's attributes.
Generally what happens because of the first three lines, in the test class, is a code coverage 100%, with that I noticed this number is not that important with this kind of classes. :\