You need to sign in to do that
Don't have an account?
Test code for a class
Hai,
I am not familiar with test class.Can anyone help me to write th test code for this class ?
public class Login{
public PageReference redirect() {
Integer total_records;
String email_login;
email_login=UserInfo.getUserName();
Http httpProtocol = new Http();
HttpRequest request = new HttpRequest();
String endpoint = 'http://50.57.52.21/salesforce/Services/validate_user_login.php?id='+email_login;
request.setEndPoint(endpoint);
request.setMethod('GET');
HttpResponse response = httpProtocol.send(request);
JSONParser parser = JSON.createParser(response.getBody());
while (parser.nextToken() != null)
{
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'total_records'))
{
// Get the value.
parser.nextToken();
// Compute the grand total price for all invoices.
total_records=integer.valueof(parser.getText());
// total_records=
}
}
if( total_records>0)
{
return Page.mkt_ana;
}
else
{
return Page.loginfailure;
}
return null ;
}
}
Hi,
The below will not cover the complete class but definatly cover some part of the class, which might be helpfull for you.
Please find the below links which will help you understaning about writing test classes.
http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_error_handling.htm
Hai,
I tried this but ,it shows only 52 % code coverage
Hi,
Yes as i said above the class will not cover completely as there is Http protocol request exist as below
HttpResponse response = httpProtocol.send(request);
Currently me too looking to cover these types of test classes.
Please update me,when you get a solution,its very urgent for me