Skip to main content
John Neff (Ring2Media) が「#Apex」で質問
Hello, 

I use a controller class format to dynamically group and display query results (bootstrapped from Jeff Douglas blog, source here) for a lot of my visualforce pages.  Here is an example of one of these classes: 

 

public with sharing class CloseQTRController

{

public List <Buyer__c> Buyer {get;set;}

public list<String> salesqtr {get;set;}

public void load()

{

salesqtr= new List<String>();

Buyer = [Select id, name, Routing_Status__c, Sales_Quarter__c, Funds_Collected_All_Time__c, Sales_Origination_Date__c, Sales_LN__c from Buyer__c WHERE Current_FQ_Buyer__c = FALSE ORDER BY Sales_Origination_Date__c ASC];

Set<String> salesqtrSet = new Set<String>();

for (Buyer__c j : Buyer)

salesqtrSet.add(j.Sales_Quarter__c);

for (String salesqtr : salesqtrSet)

{

salesqtrs.add(salesqtr);

}

salesqtrs.sort();

}

As my dependance on this technique has grown, my code coverage % has declined despite the fact that I am writing a test class for each new class created.  This leads me to believe that my test class is not sufficiently covering the class - but I do not know how to make it more efficient.  Here is a corresponding example test class: 

 

@isTest(seeAllData = false)

public class CloseQTRControllerTest{

// Unit test Method

static testmethod void UnitTest() {

//Create your buyer__c record with required field

//Buyer__c b = new Buyer(Current_FQ_Buyer__c = TRUE);

//insert b;

test.startTest();

CloseQTRControllerTest qt = new CloseQTRControllerTest();

test.stopTest();

}

}

What should I add to this test class to bring up my code coverage? 

I have not added any new classes without corresponding test classes, so I am sure it is the set of classes that use the format above that is dragging my code coverage down. 

Can anyone help!?

Thanks in advance!

John 

 
1 件の回答
  1. 2016年4月26日 12:45
    This is a duplicate ticket. Your issue is resolved on below post

    1) https://developer.salesforce.com/forums/ForumsMain?id=906F0000000Bb3zIAC

    @isTest

    public class CloseQTRControllerTest

    {

    static testmethod void UnitTest()

    {

    Buyer__c b = new Buyer();

    b.Current_FQ_Buyer__c = FALSE ;

    // add all required field here

    insert b;

    test.startTest();

    CloseQTRControllerTest qt = new CloseQTRControllerTest();

    test.stopTest();

    }

    }

    Let us know if you need more help

    Thanks

    Amit Chaudhary
0/9000