You need to sign in to do that
Don't have an account?
Test Class Coverage for If clause
Hi,
I Wrote a Test Class for a trigger.Thus Trigger related to some conditions.
This is Trigger:
trigger match_territory on Lead (before insert) {
for(lead l:trigger.new)
{
if(l.Site__c=='PressKart')
{
if(l.country!=null){
if(l.country=='AntiguaandBarbuda'){
l.country='Antigua and Barbuda';
l.Territory__c = 'Americas';
}
if(l.country=='Croatia'){
l.Territory__c = 'ROW';
}
}
}
}
}
------------------
Test Class:
@isTest
public class test_presskart {
static testMethod void testpresskart()
{
Map<String,String> cuntr1 = new Map<String,String>();
cuntr1.put('ROW','Croatia');
cuntr1.put('Americas','Antigua and Barbuda' );
List<Lead> leadlist = new List<Lead>();
for(string s:cuntr1.Keyset())
{
for(string s1:cuntr1.Values())
{
Lead l = new Lead();
l.site__c = 'presskart';
l.country = s1 ;
l.Company = 'Pressmart';
l.Status = 'Open';
l.Org_Type__c = 'ePortal';
l.LastName = 'TestingLead';
l.Frequency__c = 'Daily';
l.Phone = '9998877554';
l.Email = 'test@test.com';
l.CurrencyIsoCode = 'INR' ;
l.Territory__c = s;
l.Monthly_Rev__c = 50000.0;
leadlist.add(l);
}
}
if(leadlist.size()>0)
{
insert leadlist ;
}
}
}
Once Check it Dudes,Am getting only 45%.I Want to improve it.Can anyone suggest me.
Hi,
You code also right only the one thing is has to be changed indicated by orange fonts as you are comparing a string without spaces in trigger code:
Map<String,String> cuntr1 = new Map<String,String>();
cuntr1.put('ROW','Croatia');
cuntr1.put('Americas','AntiguaandBarbuda' );
Also you can try this one :