You need to sign in to do that
Don't have an account?

Unable to increase Test Coverage.. Pls help!!!!!
I have written a trigger to display and error if user try to create more than one record for an object.
Its working fine,
trigger ENT_Trigger_OnlyOneFund on Fund__c(before insert)
{
integer count = [select count() from Fund__c];
if(count>0)
{
for(Fund__c L : trigger.New)
{
L.addError('There can be only one record of Fund ');
}
}
}
--------------------------
Than I wrote a test class for the same which is showing me 13% test covegare.
@isTest
private class TestOnlyOneFund
{
static testMethod void validateFund()
{
Account a=new Account(Name='Test', AccountNumber='Test1');
insert a;
Fund__c c= new Fund__c(Fund_Name__c='test', Account__c=a.id);
insert c;
}
}
Please help what code I should add to increase test coverage for this class.
Thanks.
You have only created one CDFI Fund Record, so it doesn't go beyond count > 0 when the trigger is executed from the test coverage.
Simply create another record for CDFI Fund and then you'll be able to cover most of your code.
Hi Vishal,
I tried adding another record too but its giving me error which is from my trigger itself. i.e. " There can be only one record of CDFI Fund and its already existing".
Any other workaround for the same?
Check this out, I think that it can help you.
http://boards.developerforce.com/t5/Apex-Code-Development/How-do-I-test-for-an-exception-addError-in-a-Trigger/td-p/145443
This is the normal behavior of the trigger posted. To check the error put the second insert statement inside try-catch block.