You need to sign in to do that
Don't have an account?
Test Method having assertequal fail, possibly trigger issue
Here is my trigger:
trigger SetDefaultAgreementTerms on Opportunity (before insert) {
for (Opportunity o : trigger.new) {
if (o.RecordTypeId == '012300000002OYW') {
o.Agreement_TermsRTF__c = 'test';
}
}
}
And here is my test
@isTest
private class ProposalTestSuite {
static testMethod void SetDefaultAgreementTermsTest() {
test.startTest();
Account a = new account();
a.Name = 'Test1DefaultAgreementAccount';
a.RecordTypeId = '01230000000SZKW';
a.Type = 'Customer';
String acctid;
try{
insert a;
acctid = a.id;
}
catch(System.DMLException e){
system.assert(false,'Error inserting account');
}
//validate single insert
Opportunity o = new Opportunity();
o.RecordTypeId = '012300000002OYW';
o.name = 'Test2DefaultAgreementOpp';
o.AccountId = acctid;
o.StageName = 'Prospect- B';
o.CloseDate = Date.today();
try{
insert o;
}catch(System.DMLException e){
system.assert(false,'Error inserting opportunity');
}
Opportunity NewO = [select id,Agreement_TermsRTF__c from Opportunity where id= :o.Id];
System.assertEquals(NewO.Agreement_TermsRTF__c, 'test');
test.stopTest();
}
}
I have tried multiple steps to deploy these. I can't save the trigger to the server because of code coverage, and I can't get the test to pass either.
In the Apex Test Runner, I get System.Exception: Assert Fale: Expecte null, ACtual: test
It seems that my opportunity trigger isn't working, but I don't really know.
Can someone help me get from here to a deployed trigger?
I can't see anything obviously wrong with your trigger/test.
Try adding some debug to your trigger, e.g. between the for and the if, add something like:
System.debug('##### Comparing opp record type ' + o.RecordTypeId + ' to 012300000002OYW');
Plus you could add debug inside the if, and add an else with debug to indicate no match. That will at least tell you exactly what is happening inside the trigger.
That's a good idea, and something I was unaware I could do.
However, it looks like my trigger isn't saving the changes to add anything. I understand that it can't deploy unless it has the right coverage, but I am not sure how to make changes to the trigger so that my test will call it.
When I click save on my trigger it gives me the "Test coverage of selected Apex Trigger is 0% and at least 75% is required.