You need to sign in to do that
Don't have an account?
AntonyasLen
Salesforce Apex code coverage
Hi,
I searched a lot of way to improve my code and so far it was working fine.
(around 6-7 classes)
I'm currently fightinh with Strange class class, the validator stop with IF statement or Object creation...it's really crazy...
I wrote this post to ask to the community if any one got issues with the code coverage avout :
- IF statement
- Statement inside a loop ( IF inside a For ..)
- Items creation...
i found some idea on internet but i just improved my test from 10 to 23 % ...
Sincerely
Hi
trystatements try thinking of it this way -
you don't write the unit tests to get code coverage, instead you do that to check that the code behaves the way you expected.
if your unit test doesn't cover the inside of an if statement, than you probably didn't write a test scenario in which the answer to that IF is true.
for example, if I had an insert trigger with a for on the trigger.new collection and an if inside that FOR loop,like:
for(contact c : trigger.new)
{
If(c.name == 'test')
//do something
}
in order to would the //do something line, I would create a unit test that goes something like:
contact con = new contact();
con.lastName = 'test';
insert con;
this way I:
1.created data
2.Got inside a for loop
3.Got into the IF block
hope this helps
very helpfull!
But now i'm in front of an other case.
i have to test an Apex Pages :i don't know how ceate it in my apex test class, here an example