2

The problem while covering the code is that the get method is not covering, while the set method covers.

Example, below code covers (that's in blue):

public void setselectedPlanRouteId(string SelectedPlanRouteId)
{
    this.selectedPlanRouteId = SelectedPlanRouteId;
}

And the below of this line doesn't (that's in red):

public String getselectedPlanRouteId()
{
    return this.selectedPlanRouteId;
}

What goes wrong that it does not cover the code? Thanks

3
  • nothing. it depends on your functionality if you want to cover these lines or not. but as a best practices if your line is not covered in test class then you should check if you actually need those lines. Commented Apr 15, 2016 at 10:34
  • 1
    @TusharSharma Thanks. I deleted the piece of code that not usable and guess what % raised. Thanks again.
    – Viraj
    Commented Apr 15, 2016 at 11:25
  • 1
    @TusharSharma reputation below 15. though accepted the ans. thanks again.
    – Viraj
    Commented Apr 18, 2016 at 9:31

3 Answers 3

1

Nothing. it depends on your functionality if you want to cover these lines or not. but as a best practices if your line is not covered in test class then you should check if you actually need those lines.

Or another solution you can try what @croperdy suggest. Use assert to validate.

1
  • I did comment few of the properties which isn't useful anywhere further. Working fine. Also I took care of try and catch, both. Did negative testing and the overall coverage got increased significantly, which i didn't earlier. thanks again.
    – Viraj
    Commented Apr 18, 2016 at 9:33
1

Well, you could write the above logic in a more compact fashion

public selectedPlanRouteId {get; set;}

and test coverage is obtained by (assuming ctlr is a reference to the controller object)

ctlr.selectedPlanRouteId = 'foo';  // tests setter
system.assertEquals('foo',ctlr.selectedPlanRouteId);  // tests getter
1
  • I do agree about the compact fashion thing.
    – Viraj
    Commented Apr 18, 2016 at 13:49
0

call like a normal method. it cover the code

classname cn = new classname();

cn.getselectedPlanRouteId();

cn.setselectedPlanRouteId('pass string value');

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .