2

I can't quite tell why code coverage is saying that there are 0 lines covered. My objective is that every time an Award is inserted, an Award Judging Criterion is inserted with a link to the Award.

Here's my trigger code:

trigger CreateOverallCriteriaForAwardCategory on Award__c (after insert) {
    List<Award_Judging_Criterion__c> criteria = new List<Award_Judging_Criterion__c>();
    for(Award__c award : Trigger.new) {
        Award_Judging_Criterion__c criterion = new Award_Judging_Criterion__c();
        criterion.Name = 'Overall';
        criterion.Award__c = award.Id;
        criteria.add(criterion);
    }
    insert criteria;
}

And my test code:

@isTest
public with sharing class CreateOverallCriteriaForAwardTest {
    static testMethod void OverallCriteriaGetsCreated() { 
        List<Award__c> awards = new List<Award__c>();
        for (Integer i = 0; i < 10; i++) {
            Award__c award = new Award__c();
            award.Name = 'Award' + i;
            awards.add(award);
        }
        insert awards;

        Set<Id> ids = new Map<Id, Award__c>(awards).keySet();

        List<Award_Judging_Criterion__c> criteria = [ SELECT Name From Award_Judging_Criterion__c WHERE Award__c IN :ids ];

        System.assertEquals(10, criteria.size());
        for (Award_Judging_Criterion__c criterion : criteria) {
            System.assertEquals('Overall', criterion.Name);
        }
    }
}

Any help greatly appreciated.

2
  • 3
    Probably a glitch. Your code should have 100% coverage, easy. Try using Run All Tests and see if that helps, and under Test Execution, make sure that "store aggregate results" is not enabled (you want to store all results).
    – sfdcfox
    Oct 15 '14 at 14:39
  • You were right, running the tests through the Development Console gave me 100% coverage. Oct 15 '14 at 14:47
2

Try to run it via developer console and open the test execution by expading the test in test tab which is located near to the logs tab in left side below of the developer console . As shown below.

test tab

And then double click the test exection As per the above test excution its shown as myUnitTest The new window will appear in that select the test execution in the left side bar it shows what are the classes are covered in this test execution and how much percentage it is covered. As shown in below image

Test result and covereage

If you want to know which are the lines missed then you can double click on class on the left sidebar and it will open the class with blue and red lines indication which are all covered and which are all not covered .

Note : red indicated not covered lines and blue indicates covered lines.

Covered lines

You can also know which test classes covered how many percantage and what are the lines covered by clicking the drop down below the file menu. In the above image it is shown in top right corner.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.