function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
John NeffJohn Neff 

Test class isn't quite good enough - how do I beef it up?

Hello, 

I am trying to deploy a class that will allow me to group my StageName= Qualified opportunities by a custom field called vertical__c.

However, I am running into a code coverage error when trying to deploy this, as the new class is bringing my code coverage down to 73% and I admitadlly do not know near enough about test methods to bring this up.  Can anyone help?

Here is my class: 
 
public with sharing class QualOpController
{

public List <Opportunity> Opty {get;set;}
public list<String> campaigns {get;set;}

public void load() 
{
  campaigns= new List<String>();
  Opty = [Select id, name, Company_Name__c, Vertical__c, Weeks_Live__c, Days_Since_Last_Modified__c, Contract_SENT__c, NextStep, LeadSource, Probability, Spend_Last_Week__c, Spend_Last_30_Days__c, Owner_Name__c, Revenue_All_Time__c from Opportunity WHERE StageName = 'Qualified' ORDER BY Probability DESC]; 
  
  Set<String> campaignSet = new Set<String>();
  for (Opportunity j : Opty)
      campaignSet.add(j.Vertical__c);
      
      for (String campaign : campaignSet) 
      {
            campaigns.add(campaign);
      }
      campaigns.sort();
    }
}

and here is the test class that I have for it... please don't laugh: 
 
@isTest(seeAllData = false)
public class QualOpControllerTest{
    // Unit test Method
    static testmethod void UnitTest() {
        //Create your opportunity record with required field
        //Opportunity j = new Opportunity(StageName = 'Qualified');
        //insert j;
        test.startTest();
            QualOpControllerTest qo = new QualOpControllerTest();
        test.stopTest();
    }   
}

What is the best way for me to sure up this test?

Thanks in advance!

John
Best Answer chosen by John Neff
venkat-Dvenkat-D
Sorry it should be 
test.startTest();
QualOpController qo = new QualOpController();
qo.load();
test.stopTest();

Try above.

All Answers

venkat-Dvenkat-D
 test.startTest();
QualOpControllerTest qo = new QualOpControllerTest();
qo.load();
test.stopTest();

Try above.
John NeffJohn Neff
Thank you, I tried it with this syntax: 
 
@isTest(seeAllData = false)
public class QualOpControllerTest{
   
    static testmethod void UnitTest() {
    
       test.startTest();
QualOpControllerTest qo = new QualOpControllerTest();
qo.load();
test.stopTest();

    }   
}
and recieved the error: 


Error: Compile Error: Method does not exist or incorrect signature: [QualOpControllerTest].load() at line 8 column 1​

It seems I've misunderstood the syntax here
John NeffJohn Neff
Ah - I though I understood for a second here, and compiled this as: 
 
@isTest(seeAllData = false)
public class QualOpControllerTest{
    // Unit test Method
    static testmethod void UnitTest() {
        //Create your opportunity record with required field
        //Opportunity j = new Opportunity(StageName = 'Qualified');
        //insert j;
        test.startTest();
QualOpControllerTest qo = new QualOpControllerTest();
qo.load();
test.stopTest();
    }   
}

but now I am getting the error: 

Error: Compile Error: Method does not exist or incorrect signature: [QualOpControllerTest].load() at line 10 column 1

it doesn't seem to like the qu.load(); element

 
venkat-Dvenkat-D
Sorry it should be 
test.startTest();
QualOpController qo = new QualOpController();
qo.load();
test.stopTest();

Try above.
This was selected as the best answer
John NeffJohn Neff
it worked!  Successfully deployed!

Thank you so much!