0

enter image description here

I had this pagereference method, My testmethod is

static  testMethod void testvalidate()     {
        String userid = UserInfo.getUserId(); 
        Map<String, String> QR = new Map<String, String>();
        String uid = UserInfo.getUserId();
        QR = Auth.SessionManagement.getQrCode();      
        String Secret = QR.get('secret'); 
        test.startTest(); 
        String status = 'test';
        String tokenInvalid = 'test';
        System.assertEquals(tokenInvalid,'test');
        System.assertEquals(status,'test');
        TwoFactorInfo TwoFactor = new TwoFactorInfo(UserId=uid , Type='TOTP', SharedKey=Secret );
        insert(TwoFactor);                    
        PageReference pageRef = new PageReference('/home/home.jsp');
        Test.setCurrentPage(pageRef);
        AddTOTPcontroller  c = new AddTOTPcontroller();
        c.validate();
        System.assertEquals(null,c.validate());
        test.stopTest();
}
    }

Can i know why i get red lines even though i have needed test method. if i am wrong can any one help me correcting it?

1
  • 1
    As the catch(Exception ex) line is being covered it looks like your validateTotpTokenForKey method is throwing an exception. Examine the implementation and figure out what you need to setup in your test method to avoid that.
    – Keith C
    Oct 30 '15 at 14:38
0
static  testMethod void testvalidate()     {
    String userid = UserInfo.getUserId(); 
    Map<String, String> QR = new Map<String, String>();
    String uid = UserInfo.getUserId();
    QR = Auth.SessionManagement.getQrCode();      
    String Secret = QR.get('secret'); 
    test.startTest(); 

    TwoFactorInfo TwoFactor = new TwoFactorInfo(UserId=uid , Type='TOTP', SharedKey=Secret );
    insert(TwoFactor);                    
    PageReference pageRef = new PageReference('/home/home.jsp');
    Test.setCurrentPage(pageRef);
    AddTOTPcontroller  c = new AddTOTPcontroller();
   c.status = 'test';
   c.tokeninvalid = 'test';
   c.validate();
  System.assertEquals(tokenInvalid,'test');
  System.assertEquals(status,'test');
  System.assertEquals(null,c.validate());
  test.stopTest();
}
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.