I have a test class that calls methods from a class and asserts that the work done by each method meets the expected result. For some reason, even though a message is displayed saying that all test have passed when the test class is run, the code coverage for the class is still at 0%. This can be see my looking in the top tab bar in the dev console as well as by running the following query:
SELECT ApexClassOrTrigger.Name, NumLinesCovered, NumLinesUncovered
FROM ApexCodeCoverageAggregate WHERE ApexClassOrTrigger.Name = 'TestCreateCampaign'
As was outlined in the answer of this post, I made sure to actually call the methods directly from the original class. I think that there possibly could be an issue with the fact that the original class is a static class with static methods, but I'm not sure if that would prevent the system from detecting the code coverage.
What could be the issue here?
The prototypes for the original class and its methods/attributes as well as the code for the test class are below:
original class:
public class CreateCampaign {
class CampaignFrequency{}
public class AvailableMailing{}
class CampaignObj{}
public static string reformatString(String oldString){}
public static List<AvailableMailing> getAvailableMailings(){}
public static List<Campaign> upsertCampaigns(){}
public static List<CampaignMember> addCampaignMembers(){}
}
test class
@isTest
private class TestCreateCampaign {
static testMethod void runPositiveTestCases() {
//Initial test to verify that all three available mailings are selected to be used to create campaigns
System.debug('Verifying available mailings ');
CreateCampaign camp = new CreateCampaign();
camp.reformatString('test');
List<CreateCampaign.AvailableMailing> availMailings = CreateCampaign.getAvailableMailings();
Integer origIdsCount = availMailings.size();
List<Available_Mailings__c> testAvailMailings = [SELECT Id , Create_Campaign__c , Name, Mailing_Type__c, Frequency__c FROM Available_Mailings__c WHERE Create_Campaign__c = TRUE];
Integer testIdsCount = testAvailMailings.size();
for(Available_Mailings__c amc_t : testAvailMailings){
for(CreateCampaign.AvailableMailing amc : availMailings){
if(amc.MailingId == amc_t.Id){
--origIdsCount;
--testIdsCount;
}
}
}
System.assertEquals(origIdsCount, 0);
System.assertEquals(testIdsCount, 0);
//To test campaigns inserted, manually derive column (mailing_id+ _ + campaigin_key)
//and check against the variable Campaign_Key__c in the campaign model
System.debug('Verifying campaign creation');
CreateCampaign.upsertCampaigns();
List<Campaign> campaigns = [SELECT Id , Campaign_Key__c FROM Campaign WHERE Campaign_Key__c <> ''];
origIdsCount = availMailings.size();
for(CreateCampaign.AvailableMailing amc : availMailings){
for(Campaign cmp : campaigns){
if(amc.Campaign_Key == cmp.Campaign_Key__c){
--origIdsCount;
}
}
}
System.assertEquals(origIdsCount, 0);
//Test if the campaign members were added to the appropriate campaigns
System.debug('Verifying addition of campaign members to campaigns');
List<CampaignMember> members = CreateCampaign.addCampaignMembers();
Integer numMembers = members.size();
for(CampaignMember cm : members){
for(Campaign cmp : campaigns){
if(cmp.Campaign_Key__c == cm.CampaignId){
numMembers--;
}
}
}
System.assertEquals(numMembers, 0);
}
}