For a method:

public static String login(String username, String password, String startUrl) {
        ApexPages.PageReference lgn = Site.login(username, password, startUrl);
        return null;
    catch (Exception ex) {
        return ex.getMessage();            

I have this unit test:

  static void testLoginWithInvalidCredentials() {
      System.assertEquals('Argument 1 cannot be null', LightningLoginFormController.login('testUser', 'fakepwd', null));

A method "login" just throw a null - shouldn't it throw an error? This is what exception I got in my unit test:

System.AssertException: Assertion Failed: Expected: Argument 1 cannot be null, Actual: null

Should I fix a method in test or a method in a normal class?

  • You can't assume how a method has error handling implemented, though ideally the documentation should be explicit on that.
    – Keith C
    Feb 4 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.