You need to sign in to do that
Don't have an account?
Allen2
I have written the below test class for the given below apex class, It is covering 82% now unable to cover some parts, Please anyone could halp me ...
public abstract class childController extends Controller {
public Idea conIdea { get; set; }
public String conCategories {
get {
if (conCategories == null && conIdea != null) {
conCategories = conIdea.categories;
}
return conCategories;
}
set;
}
public String getVote() {
return Math.Round(conIdea.vote).format();
}
public List<String> getSplitCategories() {
if (conCategories == null) {
return new String[0];
} else {
return conCategories.split(';');
}
}
public String getCategory() {
if (conCategories == null) return null;
String[] splitCategories = getSplitCategories();
return splitCategories[splitCategories.size() - 1];
}
}
Test Class As....
@isTest
public class IdeaChildDetailsController extends IdeaDetailsAbstractController {
static testMethod void testGetters() {
IdeaTestUtil.setupTest();
childController controller = new childController();
Idea idea = IdeaTestUtil.makeIdea();
controller.conIdea = idea;
controller.conCategories = 'sigma';
controller.getSplitCategories();
String getVote;
getVote = '10';
Integer myInt = Integer.valueOf(getVote);
System.assertEquals(10, myInt);
System.assert(controller.conCategories != '');
}
static testMethod void testSplitCategories() {
IdeaTestUtil.setupTest();
childController controller = new childController();
Idea idea = IdeaTestUtil.makeIdea();
controller.conIdea = idea;
controller.conCategories = null;
controller.getSplitCategories();
controller.getCategory();
}
}
It is not covering the "
String[] splitCategories = getSplitCategories();
return splitCategories[splitCategories.size() - 1];" this portion and "getVote"
public Idea conIdea { get; set; }
public String conCategories {
get {
if (conCategories == null && conIdea != null) {
conCategories = conIdea.categories;
}
return conCategories;
}
set;
}
public String getVote() {
return Math.Round(conIdea.vote).format();
}
public List<String> getSplitCategories() {
if (conCategories == null) {
return new String[0];
} else {
return conCategories.split(';');
}
}
public String getCategory() {
if (conCategories == null) return null;
String[] splitCategories = getSplitCategories();
return splitCategories[splitCategories.size() - 1];
}
}
Test Class As....
@isTest
public class IdeaChildDetailsController extends IdeaDetailsAbstractController {
static testMethod void testGetters() {
IdeaTestUtil.setupTest();
childController controller = new childController();
Idea idea = IdeaTestUtil.makeIdea();
controller.conIdea = idea;
controller.conCategories = 'sigma';
controller.getSplitCategories();
String getVote;
getVote = '10';
Integer myInt = Integer.valueOf(getVote);
System.assertEquals(10, myInt);
System.assert(controller.conCategories != '');
}
static testMethod void testSplitCategories() {
IdeaTestUtil.setupTest();
childController controller = new childController();
Idea idea = IdeaTestUtil.makeIdea();
controller.conIdea = idea;
controller.conCategories = null;
controller.getSplitCategories();
controller.getCategory();
}
}
It is not covering the "
String[] splitCategories = getSplitCategories();
return splitCategories[splitCategories.size() - 1];" this portion and "getVote"
Try using assert to test the returning result from controller.getCategory() to see if it is null, then you can trace it from there.
if (conCategories == null) return null;" this one and in 2nd method I m using the code u provide me where the null value not returning then it should work, but it is not and also this portion " public String getVote() {
return Math.Round(conIdea.vote).format();" not covering.