You need to sign in to do that
Don't have an account?
venkyyy
Apex Test Class Needs to get 100% code coverage
Hi all,
I have created a small example class which is copied bellow and also test class to that, it is running fine but the code coverage was 75% only,
what i need to add if i want to get 100% of code covearage., please help me out from this, Thanks in advance
The class is:
public class ex2 {
public integer a,b,c;
public void dis(){
if(a>b){
c = a + b;
}
else {
c = a - b;
}
}
}
Test Class is:
-----------------
@isTest
public class ex2Tesst{
public static testmethod void ex2tesstmethod01(){
ex2 e = new ex2();
e.a = 2;
e.b = 1;
e.dis();
}
public static testmethod void ex2tesstmethod02(){
ex2 e1 = new ex2();
e1.a = 2;
e1.b = 1;
e1.dis();
}
}
I have created a small example class which is copied bellow and also test class to that, it is running fine but the code coverage was 75% only,
what i need to add if i want to get 100% of code covearage., please help me out from this, Thanks in advance
The class is:
public class ex2 {
public integer a,b,c;
public void dis(){
if(a>b){
c = a + b;
}
else {
c = a - b;
}
}
}
Test Class is:
-----------------
@isTest
public class ex2Tesst{
public static testmethod void ex2tesstmethod01(){
ex2 e = new ex2();
e.a = 2;
e.b = 1;
e.dis();
}
public static testmethod void ex2tesstmethod02(){
ex2 e1 = new ex2();
e1.a = 2;
e1.b = 1;
e1.dis();
}
}
The ex2Tesstmethod02 is exactly the ex2tesstmethod01 so it won't cover the else part.
Le
Now the code was 100%.
If possible send me some basic examples for test classes along with the classes, i have to practice more on apex classes and triggers too..., getting so much confidance while practicing.
Thanks in advance again Le Nguyen.
Please drop a mail some examples.