You need to sign in to do that
Don't have an account?
Test Coverage for a trigger 55%. Must be 75%...
Dear all,
I have created the following test class to test a trigger that works. The trigger changes the value on a dependend object's picklist according to the choice of the parent object.
The test reaches only 55%.
It needs to reach 75% coverage.
Below is the test code and way beyod the trigger.
Any suggestions are more than welcome!
Test Code:
@isTest
public class testChangeofStatusinAssociate {
static testMethod void testChangeofStatusinAssociate(){
List<Account> accounts = new List<Account>{};
for(Integer i = 0; i < 30; i++){
Account a = new Account(Name = 'Test Account ' + i,
Associate_s_Title__c='dd',Status__c='Under Deactivation');
accounts.add(a);
List<Location__c> Location = new List<Location__c>{};
Location__c b = new Location__c(Location_Name__c='AAA',
Status__c='Under Deactivation');
Location.add(b);
insert Location;
}
test.startTest();
insert accounts;
test.stopTest();
}
}
Trigger:
trigger updateactive on Account (after update, after insert){
Location__c[] StatusToUpdate = new Location__c[]{};
for(Account c : trigger.new ){
for(Location__c cp: [
select id,name,Status__c from Location__c
where Associate__c =:c.id]){
if ( c.Status__c == 'Under Deactivation'){
cp.Status__c = 'Under Deactivation';
}
StatusToUpdate.add(cp);
}
}
if(StatusToUpdate.size()>0)
update StatusToUpdate;
}
Hi
U just insert the Location__c
Try this
@isTest
public class testChangeofStatusinAssociate {
static testMethod void testChangeofStatusinAssociate(){
List<Account> accounts = new List<Account>{};
for(Integer i = 0; i < 30; i++){
Account a = new Account(Name = 'Test Account ' + i,
Associate_s_Title__c='dd',Status__c='Under Deactivation');
accounts.add(a);
List<Location__c> Location = new List<Location__c>{};
Location__c b = new Location__c(Location_Name__c='AAA',
Status__c='Under Deactivation');
insert b;
}
test.startTest();
insert accounts;
test.stopTest();
}
}
Hi dude,
Thanks, I tried it but it keeps giving a 55%.
All the best,
Hi
Please provide the lines which r not covered.
Hi,
I have all the code posted above, the trigger and the test class.
When I give it a run test, it stucks at 55%.
The trigger works fine when I test it manually.
All the best,
Have you tried using the web interface to run the test? It provides a handy tool to show you which lines of code have not been run. Navigate to your test class, hit Run Test, check the Trigger Code Coverage section and look for your trigger. Next to it's name, there's a percentage coverage value that you can click on to get the visual - you'll quickly be able to see which areas you have not covered.
Thanks dude,
It gave a good light there...
all the best,