Skip to main content
added 183 characters in body
Source Link
BarCotter
  • 12.4k
  • 4
  • 38
  • 58

The reason you are not getting full test coverage is because you are not inserting the Contact record, so the code would not of been iterating over the for loop in your code.

This code should give you full test coverage:

@isTest
public class emailCon1_Tc
{
    static testMethod void testMthd() {
        String email = '[email protected]';
        String lastName = 'YYY';
        Contact c = new Contact(LastName = lastName, Email = email);
        insert c;
        emailCon1_Tc ec = new emailCon1_Tc();

        System.assertEquals(1, ec.con.size());
        System.assertEquals(c.Id, ec.con[0].Id);

        System.assertEquals(lastName, ec.m.get(email));
    }
}

This code should give you full test coverage:

@isTest
public class emailCon1_Tc
{
    static testMethod void testMthd() {
        String email = '[email protected]';
        String lastName = 'YYY';
        Contact c = new Contact(LastName = lastName, Email = email);
        insert c;
        emailCon1_Tc ec = new emailCon1_Tc();

        System.assertEquals(1, ec.con.size());
        System.assertEquals(c.Id, ec.con[0].Id);

        System.assertEquals(lastName, ec.m.get(email));
    }
}

The reason you are not getting full test coverage is because you are not inserting the Contact record, so the code would not of been iterating over the for loop in your code.

This code should give you full test coverage:

@isTest
public class emailCon1_Tc
{
    static testMethod void testMthd() {
        String email = '[email protected]';
        String lastName = 'YYY';
        Contact c = new Contact(LastName = lastName, Email = email);
        insert c;
        emailCon1_Tc ec = new emailCon1_Tc();

        System.assertEquals(1, ec.con.size());
        System.assertEquals(c.Id, ec.con[0].Id);

        System.assertEquals(lastName, ec.m.get(email));
    }
}
Source Link
BarCotter
  • 12.4k
  • 4
  • 38
  • 58

This code should give you full test coverage:

@isTest
public class emailCon1_Tc
{
    static testMethod void testMthd() {
        String email = '[email protected]';
        String lastName = 'YYY';
        Contact c = new Contact(LastName = lastName, Email = email);
        insert c;
        emailCon1_Tc ec = new emailCon1_Tc();

        System.assertEquals(1, ec.con.size());
        System.assertEquals(c.Id, ec.con[0].Id);

        System.assertEquals(lastName, ec.m.get(email));
    }
}