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
betterbhushanbetterbhushan 

How to write test for following part of apex code? I am fairly new to sfdc development.

public with sharing class ddDashboard {

 public class phonesterDat{

  String type;
  Integer total;
  Integer valid;

  public String getType() {
   return type;
  }

  public void setType(String type){
   this.type= type;
  }

  public Integer getTotal() {
   return total;
  }
  public void setTotal(Integer total){
   this.total= total;
  }

  public Integer getValid() {
   return valid;
  }
  public void setValid(Integer valid){
   this.valid= valid;
  }

}
 public List<phonesterDat> getEmailData() {
 List<phonesterDat> var1 = new List<phonesterDat>();
 phonesterDat var = new phonesterDat();
 var.setType('Contact Email');
 var.setTotal([select count() from Contact where Email != null]);
 var.setValid([select count() from Contact where Email_Valid__c = true]);
 var1.add(var);
 return var1;
}


public List<phonesterDat> getCompanyData() {
List<phonesterDat> var1 = new List<phonesterDat>();
List<Account> accounts = [select DD_Segment__c from Account];
List<Keyword__c> keywords = [select kw__c from Keyword__c limit 50000];
for (Keyword__c keyword : keywords) {
 phonesterDat var = new phonesterDat();
 String str = keyword.kw__c;
 var.setType(str);
 Integer cnt = 0;
 for (Account acc : accounts) {
  if (acc.DD_Segment__c != null && acc.DD_Segment__c.contains(str)) {
    cnt = cnt+1;
 }
}
var.setTotal(cnt);
var1.add(var);
}
return var1;
}

}

 How to write test coverage for above code?

RollNo1RollNo1

Reference: http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods

 

@isTest
private class TestddDashboard
{
static testMethod void TestphoneterDat()
{
ddDashboard d = new ddDashboard();

d.getType();
d.setType();
d.getTotal();
d.setTotal();
d.getValid();
d.setValid();
d.getEmailData();
d.getCompanyData();
}
}

 

Try this...

betterbhushanbetterbhushan

I don't think thats right way to do it. Security code review might reject this kind of tests