Test method which asserts expected and actual URL fails on PROD while there are no issues on a sandbox. PROD has the actual sessionId in the URL, while sessionId value at a sandbox is: SessionId=00De0000000abcZ%21ApexTestSession
Is it possible that the actual sessionId in a test method is causing problem at PROD?
Solution
We have changed test method to determine which parameter actually causes the issue and found out sessionID comparison results in a failure indeed. This issue is only reproducible on PROD while it works fine on a sandbox due to difference in how sessionID is generated in a test method based on the env.
Salesforce support indicated this is as expected and did not provide technical details for the issue.
Failure Message on PROD: "System.AssertException: Assertion Failed: Parameter: SessionId mismatch: Expected: 00D30000000abcZ!ARcAQEGRFJyOj........., Actual: 00D30000000abcZ!ARcAQJSCH2mOlknHRvf.......
Below is the sample code to reproduce assert failure on PROD.
public class MySession{
public static String getSessionId() {
return UserInfo.getSessionId();
}
}
@isTest
public class MySessionTest{
@isTest static void getSessionIdShouldBeSameAsUserInfoSessionId() {
String expected = UserInfo.getSessionId();
String actual = MySession.getSessionId();
System.debug('Expected: ' + expected + ', Actual: ' + actual);
System.assertEquals(expected, actual);
}
}
**FYI: there was one more issue generated on PROD only in a test method comparing Salesforce standard URL. When testing standardController.delete(), the URL in PROD has confirmation token which is not present on any sandbox. As a resolution, we have changed test method to compare only parameters we are interested in and not complete URL.
Sample URL generated on PROD in a test method: /setup/own/deleteredirect.jsp?CONFIRMATIONTOKEN=......&delID=a2ha0000000abcX&nooverride=1&retURL=%2Fa2h%2Fo...