You need to sign in to do that
Don't have an account?
Shruthi GM 4
Test class for a Lightning class:-
/* Class */
global class LightningForgotPasswordController {
public LightningForgotPasswordController() {
}
@AuraEnabled
public static String forgotPassowrd(String username, String checkEmailUrl) {
try {
Site.forgotPassword(username);
ApexPages.PageReference checkEmailRef = new PageReference(checkEmailUrl);
if(!Site.isValidUsername(username)) {
return Label.Site.invalid_email;
}
aura.redirect(checkEmailRef);
return null;
}
catch (Exception ex) {
return ex.getMessage();
}
}
}
/* test class */
@istest
public class LightningForgotPasswordControllertest{
public static testmethod void testvalidate(){
String username='shrugm@tcs.com';
String checkEmailUrl='aabgfgb';
test.starttest();
LightningForgotPasswordController lightningForgot=new LightningForgotPasswordController();
LightningForgotPasswordController.forgotPassowrd('shrugm@tcs.com','aabgfgb');
test.stoptest();
}
}
it is covering 63% of the code.Please help me to cover the entire class!
global class LightningForgotPasswordController {
public LightningForgotPasswordController() {
}
@AuraEnabled
public static String forgotPassowrd(String username, String checkEmailUrl) {
try {
Site.forgotPassword(username);
ApexPages.PageReference checkEmailRef = new PageReference(checkEmailUrl);
if(!Site.isValidUsername(username)) {
return Label.Site.invalid_email;
}
aura.redirect(checkEmailRef);
return null;
}
catch (Exception ex) {
return ex.getMessage();
}
}
}
/* test class */
@istest
public class LightningForgotPasswordControllertest{
public static testmethod void testvalidate(){
String username='shrugm@tcs.com';
String checkEmailUrl='aabgfgb';
test.starttest();
LightningForgotPasswordController lightningForgot=new LightningForgotPasswordController();
LightningForgotPasswordController.forgotPassowrd('shrugm@tcs.com','aabgfgb');
test.stoptest();
}
}
it is covering 63% of the code.Please help me to cover the entire class!
Try below class and let me know if it works. This class should give you 100% coverage.
Its throwing an exception, that is why you are getting this error. Lets put a try catch block around the piece of code when we are passing invalid parameters.