You need to sign in to do that
Don't have an account?
Apex test method with AssertEquals fails when values are equal?
I have a simple apex controller extension and created a basic unit test to verify the returned page reference from the controller is expected value.
When I run the test I get failure with below message - clearing showing the values do match???
System.AssertException: Assertion Failed: Page Reference should be for the Opportunity:
Expected: System.PageReference[/0065B000007l82WQAQ],
Actual: System.PageReference[/0065B000007l82WQAQ]
Here is test code:
@isTest
static void testOppContractCreateNotCreated() { /* opportunity stage is not set to correct value for contract create */
setupTestData();
PageReference expectRef = new PageReference('/' + opp.Id);
Test.startTest();
stdCont = new ApexPages.Standardcontroller(opp);
contExt = new OpportunityCreateContractContExt(stdCont);
PageReference createContractPageRef = Page.createAdSalesContract;
Test.setCurrentPage(createContractPageRef);
PageReference goToRef = contExt.getgoToContract();
system.debug(opp);
system.debug(goToRef);
Test.stopTest();
system.assertEquals(expectRef, goToRef,'Page Reference should be for the Opportunity');
}
When I run the test I get failure with below message - clearing showing the values do match???
System.AssertException: Assertion Failed: Page Reference should be for the Opportunity:
Expected: System.PageReference[/0065B000007l82WQAQ],
Actual: System.PageReference[/0065B000007l82WQAQ]
Here is test code:
@isTest
static void testOppContractCreateNotCreated() { /* opportunity stage is not set to correct value for contract create */
setupTestData();
PageReference expectRef = new PageReference('/' + opp.Id);
Test.startTest();
stdCont = new ApexPages.Standardcontroller(opp);
contExt = new OpportunityCreateContractContExt(stdCont);
PageReference createContractPageRef = Page.createAdSalesContract;
Test.setCurrentPage(createContractPageRef);
PageReference goToRef = contExt.getgoToContract();
system.debug(opp);
system.debug(goToRef);
Test.stopTest();
system.assertEquals(expectRef, goToRef,'Page Reference should be for the Opportunity');
}
All Answers