My issue is that although my test class (below) passes, I am getting 0% test coverage on the trigger. Not sure why?!!
Below are my trigger and test class:
Here's my trigger:
trigger AgreementAddQuoteId on echosign_dev1__SIGN_Agreement__c (before update)
{
list<Id> oppyIds = new list<Id>{};
for(echosign_dev1__SIGN_Agreement__c e : Trigger.new)
{
oppyIds.add(e.echosign_dev1__Opportunity__c);
}
map<Id,Quote> qtMap = new map<Id,Quote>([SELECT Id FROM Quote WHERE OpportunityId IN :oppyIds ORDER BY Id DESC LIMIT 1]);
for (Id idKey : qtMap.keyset ())
for(echosign_dev1__SIGN_Agreement__c e : Trigger.new)
{
Quote q = qtMap.get(idKey);
If(e.echosign_dev1__Opportunity__c != null)
{
e.Quote__c = q.Id;
System.debug(q.Id);
System.debug(e.Id);
System.debug(e.echosign_dev1__Opportunity__c);
}
}
}
And my Test Class:
@isTest
private class TestAgreementAddQuoteId {
private static testMethod void test()
{
Map <String ,ID> profiles = new Map<String,ID>();
List<Profile> ps = [select id, name from Profile where name='System Administrator'];
Map<String,ID> roles = new Map<String, ID>();
List<UserRole> urs = [select id, name from UserRole where DeveloperName = 'XXXX'];
for (Profile p : ps){
profiles.put(p.name,p.id);
}
for (UserRole u : urs){
roles.put(u.DeveloperName,u.id);
}
User testUser1 = new User (firstname='test',
lastname='User5',
Alias= 'user1',
Email='[email protected]',
Username='[email protected]',
CommunityNickname='test1',
profileid = profiles.get('System Administrator'),
languagelocalekey='en_US',
localesidkey='en_US',
timezonesidkey='America/New_York',
userroleid = roles.get('XXXX'),
emailencodingkey='UTF-8',
Phone='5851234567');
insert testUser1;
User tu1 = [select id from User where name ='test User5'];
Account a1 = new Account (name='Parent Account1',Industry='Finance');
insert a1;
Contact ct1 = new Contact (FirstName = 'testContactFirst',LastName= 'testContactLast',
Ownerid=tu1.id, Phone='5555555555', Email='[email protected]');
insert ct1;
Opportunity o1 = new Opportunity (CloseDate = Date.today()+1, Name = 'opportunity test', StageName = 'SQL', LeadSource = 'Self-Developed',
Description = 'Test Description', AccountId = a1.Id);
insert o1;
Quote q1 = new Quote (OpportunityId = o1.Id, ContactId = ct1.Id);
Quote q2 = new Quote (OpportunityId = o1.Id, ContactId = ct1.Id);
test.startTest();
echosign_dev1__SIGN_Agreement__c agr1 = new echosign_dev1__SIGN_Agreement__c (echosign_dev1__Opportunity__c = o1.Id);
insert agr1;
test.stopTest();
echosign_dev1__SIGN_Agreement__c testagr =[SELECT Quote__c,echosign_dev1__Opportunity__c from echosign_dev1__SIGN_Agreement__c WHERE Id = : agr1.Id];
System.assertEquals(q2.id, testagr.Quote__c);
System.assertEquals(o1.id, testagr.echosign_dev1__Opportunity__c);
}
}