You need to sign in to do that
Don't have an account?
Mecrin Luvis 10
Test Class2
Hi Guys,
I have created VF page and Apex class for Login Page. I want to write a test class for that login page.Please help .
VF Page:
<apex:page showHeader="false" controller="TestPage">
<center>
<apex:form >
<apex:panelGrid >
<apex:pageBlock title="LoginPage" >
<apex:pageMessages id="msg"></apex:pageMessages>
<apex:pageBlockSection >
<p><b>UserName</b><br /><apex:inputText required="true" id="username" value="{!username}"/></p>
<p><b>Password</b><br/><apex:inputSecret id="password" value="{!password}" /><br/></p>
</apex:pageBlockSection>
<apex:pageBlockButtons location="bottom"><apex:commandButton action="{!login}" value="login" id="login"/></apex:pageBlockButtons>
</apex:pageBlock></apex:panelGrid>
</apex:form>
</center>
</apex:page>
Apex Class:
public class TestPage {
public String password { get; set; }
public String username { get; set; }
public PageReference login()
{
if (username == null)
{
PageReference newPage = new PageReference('/apex/ThankYou');
newPage.setRedirect(true);
return newPage;
}
else
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please enter value'));
return null;
}
}
}
I want to write a test class for that login Page. I dont know how to write test class.Please help me to reach out to that target.
Regards,
M.D.Luvis.
I have created VF page and Apex class for Login Page. I want to write a test class for that login page.Please help .
VF Page:
<apex:page showHeader="false" controller="TestPage">
<center>
<apex:form >
<apex:panelGrid >
<apex:pageBlock title="LoginPage" >
<apex:pageMessages id="msg"></apex:pageMessages>
<apex:pageBlockSection >
<p><b>UserName</b><br /><apex:inputText required="true" id="username" value="{!username}"/></p>
<p><b>Password</b><br/><apex:inputSecret id="password" value="{!password}" /><br/></p>
</apex:pageBlockSection>
<apex:pageBlockButtons location="bottom"><apex:commandButton action="{!login}" value="login" id="login"/></apex:pageBlockButtons>
</apex:pageBlock></apex:panelGrid>
</apex:form>
</center>
</apex:page>
Apex Class:
public class TestPage {
public String password { get; set; }
public String username { get; set; }
public PageReference login()
{
if (username == null)
{
PageReference newPage = new PageReference('/apex/ThankYou');
newPage.setRedirect(true);
return newPage;
}
else
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please enter value'));
return null;
}
}
}
I want to write a test class for that login Page. I dont know how to write test class.Please help me to reach out to that target.
Regards,
M.D.Luvis.
I got the
Error: Compile Error: Illegal modifier on local variable at line 6 column 21
For This,
@isTest
public class test1
{
public static testMethod void testExample()
{
public String password;
public String username;
TestPage tp=new TestPage();
tp.login();
}
}
I resolved that, We should not define the acess modifire inside of test method.
@isTest
public class test1
{
public static testMethod void testExample()
{
String password;
String username;
TestPage tp=new TestPage();
tp.login();
}
}
All Answers
try below code......it may help u..
@isTest
public class test1
{
public static testMethod void testExample()
{
public String password;
public String username;
TestPage tp=new TestPage();
tp.login()
}
}
I got this Error.
[Error] Error: Compile Error: expecting a semi-colon, found '}' at line 10 column 0
Regard,
Mecrin.
I have replaced that. But I gor the same Error for that.
Error: Compile Error: Illegal modifier on local variable at line 6 column 15
@isTest
public class test1
{
public static testMethod void testExample()
{
public String password;
public String username;
TestPage tp=new TestPage();
tp.login();
}
}
I got the
Error: Compile Error: Illegal modifier on local variable at line 6 column 21
For This,
@isTest
public class test1
{
public static testMethod void testExample()
{
public String password;
public String username;
TestPage tp=new TestPage();
tp.login();
}
}
I resolved that, We should not define the acess modifire inside of test method.
@isTest
public class test1
{
public static testMethod void testExample()
{
String password;
String username;
TestPage tp=new TestPage();
tp.login();
}
}