• chinna neelam
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
HI, 
I am trying to cover the below apex class, but i am not able to get more than 70% of coverage. can you plaese help me how to write a proper test class. Thanks in advance.

apex controller:

public class ContactForAccountEx {
    public string accName {get;set;}
    public List<contact> cons {get;set;}
    public ContactForAccountEx(){
        cons=new List<contact>();
    }
    public void show(){
        List<account> acc=[select id,name,(select id,lastName,firstName,phone from contacts) from account where name=:accName];
        if(acc.size()>0){
            for(account a:acc){
                for(contact c:a.contacts){
                    cons.add(c);
                }
            }
           }
   }
}


My Test class is..

@isTest
private class MyTest {
    private testMethod static void testMe(){
        string str='sakshi';
        test.startTest();
        ContactForAccountEx s=new ContactForAccountEx();
        s.show();
        test.stopTest();
    }
}
HI, 
I am trying to cover the below apex class, but i am not able to get more than 70% of coverage. can you plaese help me how to write a proper test class. Thanks in advance.

apex controller:

public class ContactForAccountEx {
    public string accName {get;set;}
    public List<contact> cons {get;set;}
    public ContactForAccountEx(){
        cons=new List<contact>();
    }
    public void show(){
        List<account> acc=[select id,name,(select id,lastName,firstName,phone from contacts) from account where name=:accName];
        if(acc.size()>0){
            for(account a:acc){
                for(contact c:a.contacts){
                    cons.add(c);
                }
            }
           }
   }
}


My Test class is..

@isTest
private class MyTest {
    private testMethod static void testMe(){
        string str='sakshi';
        test.startTest();
        ContactForAccountEx s=new ContactForAccountEx();
        s.show();
        test.stopTest();
    }
}