You need to sign in to do that
Don't have an account?
venky reddy 6
write a Test class for a piece of code
public class Test
{
public pagerefernce testmethod()
{
if(input.length() == 3 && input.subString(0,1) == char1 && input.subString(1,2) == char2 && input.subString(2,3) == char3)
{
stmt;
}
else
{
stmt;
}
}
}
{
public pagerefernce testmethod()
{
if(input.length() == 3 && input.subString(0,1) == char1 && input.subString(1,2) == char2 && input.subString(2,3) == char3)
{
stmt;
}
else
{
stmt;
}
}
}
Do keep this in mind though. Your Test Class is essentially performing the same function as you manually going in and executing the actions that would make your code run.
So let's say you write a trigger to create a Case any time an Account is created. To manually test the functionality you would go to the Accounts Tab and create an Account. In the test class you'd write code that would Create an Account sObject, and then insert it. Bam, 100% coverage :-)
Then you can do an assert to verify that the Case exists for the Account.
Thanks for giving the reply
public class captcha
{
List<String> characters;
public String input {get; set;}
public String result {get; set;}
String char1;
String char3;
String char5;
//In our contructor we will populate a list of strings with numbers and letters
public captcha()
{
characters = new List<String>{'a','b','c','d','e','f','g','h', 'i','j','k','l','m','n','o','p','q','r','s','t','u','v','w', 'x','y','z','1','2','3','4','5','6','7','8','9','0' };
}
//This methods simply returns a random number between 0 and the size of the character list
public Integer randomNumber()
{
Integer random = Math.Round(Math.Random() * characters.Size());
if(random == characters.size()){ random--; } return random; }
/*Here we have 6 get methods that return 6 random characters to the page. For chars 1,3, and 5 (the black characters) we are saving the the values so that we can compare them with the user's input */
public String getChar1()
{
char1 = characters[randomNumber()];
return char1;
}
public String getChar2()
{
return characters[randomNumber()];
}
public String getChar3()
{
char3 = characters[randomNumber()];
return char3;
}
public String getChar4()
{
return characters[randomNumber()];
}
public String getChar5()
{
char5 = characters[randomNumber()];
return char5;
}
public String getChar6()
{
return characters[randomNumber()];
}
/*In the validate method we make sure that the 3 characters entered equal the three black characters: char1, char3, char5*/
public void validate()
{
if(input.length() == 3 && input.subString(0,1) == char1 && input.subString(1,2) == char3 && input.subString(2,3) == char5)
{
result = 'Whoohoo! You got it right.';
}
else
{
result = 'Come on...the letters aren\'t even disfigured.';
}
}
}
This is my class i need for test class for this, it is captcha code. can you help me this
Thanks
venkat
Below is how I would test the validate method (both a positive test and a negative test)
This should get you coverage on your validation methods, and should get you started on how the test methods should look for your other getChar* methods.
Thanks for your helping. it is working fine.