You need to sign in to do that
Don't have an account?

Testing a visualforce page
hey there,
I've just stated using salesforce and apex and I'd like to have some help with my testing methods. If anyone can helpl plz i'd be gratefull !
Here's the visualforce page code :
<apex:page controller="progress_bar">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<apex:pageblock title="Feedbacks by Severity">
<form>
<center>
<br/> <br/> <br/> <br/>
<div class="progress">
<div class="progress-bar progress-bar-striped progress-bar-success" role="progressbar" style="width:35%">
{!Normal} Normal
</div>
<div class="progress-bar progress-bar-striped active progress-bar-warning" role="progressbar" style="width:20%">
{!Blocking} Blocking
</div>
<div class="progress-bar progress-bar-striped progress-bar-danger" role="progressbar" style="width:20%">
{!Urgent} Urgent
</div>
</div>
</center>
</form>
<style>
.progress {
color : white;
font-weight : bold;
font-size : 100%;
}
</style>
</apex:pageblock>
</apex:page>
and the apex class used :
public class progress_statut {
public integer getNew(){
return [select count() from feedbacks__c where Feedback_statut__c='New'];
}
public integer getAssigned(){
return [select count() from feedbacks__c where Feedback_statut__c='Assigned'];
}
public integer getAssignedEditor(){
return [select count() from feedbacks__c where Feedback_statut__c='Assigned to Editor'];
}
public integer getInformationNeeded(){
return [select count() from feedbacks__c where Feedback_statut__c='Information Needed'];
}
public integer getEffortEstimation(){
return [select count() from feedbacks__c where Feedback_statut__c='Effort Estimation'];
}
public integer getwillnotfix(){
return [select count() from feedbacks__c where Feedback_statut__c='Will not fix'];
}
public integer getresolved(){
return [select count() from feedbacks__c where Feedback_statut__c='Resolved'];
}
public integer getdelivered(){
return [select count() from feedbacks__c where Feedback_statut__c='Delivered'];
}
public integer getclosed(){
return [select count() from feedbacks__c where Feedback_statut__c='Closed'];
}
}
Thanks for the help in advance !!
I've just stated using salesforce and apex and I'd like to have some help with my testing methods. If anyone can helpl plz i'd be gratefull !
Here's the visualforce page code :
<apex:page controller="progress_bar">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<apex:pageblock title="Feedbacks by Severity">
<form>
<center>
<br/> <br/> <br/> <br/>
<div class="progress">
<div class="progress-bar progress-bar-striped progress-bar-success" role="progressbar" style="width:35%">
{!Normal} Normal
</div>
<div class="progress-bar progress-bar-striped active progress-bar-warning" role="progressbar" style="width:20%">
{!Blocking} Blocking
</div>
<div class="progress-bar progress-bar-striped progress-bar-danger" role="progressbar" style="width:20%">
{!Urgent} Urgent
</div>
</div>
</center>
</form>
<style>
.progress {
color : white;
font-weight : bold;
font-size : 100%;
}
</style>
</apex:pageblock>
</apex:page>
and the apex class used :
public class progress_statut {
public integer getNew(){
return [select count() from feedbacks__c where Feedback_statut__c='New'];
}
public integer getAssigned(){
return [select count() from feedbacks__c where Feedback_statut__c='Assigned'];
}
public integer getAssignedEditor(){
return [select count() from feedbacks__c where Feedback_statut__c='Assigned to Editor'];
}
public integer getInformationNeeded(){
return [select count() from feedbacks__c where Feedback_statut__c='Information Needed'];
}
public integer getEffortEstimation(){
return [select count() from feedbacks__c where Feedback_statut__c='Effort Estimation'];
}
public integer getwillnotfix(){
return [select count() from feedbacks__c where Feedback_statut__c='Will not fix'];
}
public integer getresolved(){
return [select count() from feedbacks__c where Feedback_statut__c='Resolved'];
}
public integer getdelivered(){
return [select count() from feedbacks__c where Feedback_statut__c='Delivered'];
}
public integer getclosed(){
return [select count() from feedbacks__c where Feedback_statut__c='Closed'];
}
}
Thanks for the help in advance !!
Then in test class create a method and then create object of your controller class.
Now you need to call the merhods present in the controller class i.e getNew, getAssigned and store their output in some related datatypes. To achieve code coverage this is OK. But recommended way is to also check whether the output is accurate or not using asserts. In your case its simpler. For ex:
So this will compare the count returned by your SOQL and by your method.
In case you find this helpfull. Please mark this as a best answer to help others.
Thanks..
All Answers
Then in test class create a method and then create object of your controller class.
Now you need to call the merhods present in the controller class i.e getNew, getAssigned and store their output in some related datatypes. To achieve code coverage this is OK. But recommended way is to also check whether the output is accurate or not using asserts. In your case its simpler. For ex:
So this will compare the count returned by your SOQL and by your method.
In case you find this helpfull. Please mark this as a best answer to help others.
Thanks..
I have another question concerning the tests but this time its about test methods for classes using a standard controller; I managed to write this part of the class test for now and it only gives me 60% code coverage. Do you plz have any idea to improve it.
Apex class :
public class feedbackStatuts {
public String feedback_status {get; set;}
private String status;
public feedbackStatuts(ApexPages.StandardController stdController) {
//Initialisation de variables
feedback_status = '';
status = ApexPages.currentPage().getParameters().get('Feedback_statut__c');
if (status=='New'){
status='Assigned';
} else if (status=='Assigned'){
status='Assigned to editor';
} else if (status=='Assigned to editor'){
status='Information Needed';
} else if (status=='Information needed'){
status='Effort estimation';
} else if (status=='Effort estimation'){
status='Will not fix';
} else if (status=='Will not fix'){
status='Resolved';
}else if (status=='Resolved'){
status='Delivered';
}else if (status=='Delivered'){
status='Closed';
}
}
}
and the test class that 've written for now is like :
@isTest
public class feedbackStatutsTest {
static testMethod void feedbackStatutsTest() {
Feedbacks__c f = new Feedbacks__c(Name = 'trial',Feedback_statut__c='New');
System.debug('Feedback status before change ' + f.Feedback_statut__c);
Insert f;
Test.StartTest();
ApexPages.StandardController sc = new ApexPages.StandardController(f);
feedbackStatuts FB = new feedbackStatuts(sc);
PageReference pageRef = Page.change_status;
pageRef.getParameters().put('Id',f.id);
Test.setCurrentPage(pageRef);
Test.StopTest();
}
}
Thanks for the help :) !
You have to write code which sets parameter as per your different if conditions i.e New, Assigned, Assigned to editor etc. So for every condition write above line to set the different parameters value. And hence you can achieve full coverage.
So Gratefull :)