• SFBen
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

Recently I've been attempting to reduce test methods so that deployments are quicker by first identifying duplicate test methods, deleting them and rerunning test methods to check the code coverage.  Unfortunately I seem to be hitting a problem where rerunning the test methods shows no change in the code coverage - I found this quite odd as I thought there would be a few percentage increase/decreases (tested with classes that I knew would have less coverage and still no change).  

 

If I clear out the test history and rerun the tests all is fine so it seems to be a problem with Salesforce storing the percentage coverage for tests but not updating this when tests are rerun.  I've had different results when running all tests and running individual classes as well.  When looking at this problem I've mostly been looking at the code coverage at the bottom of a test execution, but noticed occurences when looking at the code coverage on the list of apex classes.  As mentioned clearing out the test history solves the issue but I think there shouldn't be an issue at all - rerunning tests should replace the code coverage from the previous test run.

  • July 15, 2011
  • Like
  • 0

I have a very simple Batch class and I am trying to write a unit test to cover it but the execute method in this batch class is never executing. I'm stumped.

 

Batch Class:

global class ideaCleanBatch implements Database.Batchable<sObject>{

global Database.QueryLocator start(Database.BatchableContext bc){
//We want to process all Ideas
return Database.getQueryLocator('select Id from Idea');
}

global void execute(Database.BatchableContext bc, List<sObject> objects){
Set<Id> ideaIds = new Set<Id>();
for(sObject s : objects){
Idea i = (Idea)s;
ideaIds.add(i.Id);
}
//Send ideas to ideaClean for processing
ideaClean.recalcNumbers(ideaIds);
}

global void finish(Database.BatchableContext bc){
system.debug('All done.');
}
}

Test Method:

static testMethod void ideaBatchTest(){
List<Idea> ideas = new List<Idea>();
Id communityId = [select Id from Community limit 1].Id;
for(Integer i = 0; i < 200; i++){
ideas.add(new Idea(Title = 'myIdea' + i, CommunityId = communityId));
}
insert ideas;

Test.startTest();
ideaCleanBatch job = new ideaCleanBatch();
ID batchprocessid = Database.executeBatch(job);
Test.stopTest();
}

Coverage:

 

Thanks,

Jason

 

  • October 30, 2009
  • Like
  • 0