function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
venkyyyvenkyyy 

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();
    }
}
Le NguyenLe Nguyen
Hi venkat,
The ex2Tesstmethod02 is exactly the ex2tesstmethod01 so it won't cover the else part.
 
@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;

//Change to this
        e1.a = 1;
        e1.b = 2;
        e1.dis();
    }
}

Le
venkyyyvenkyyy
Thanq so much Le Nguyen, 
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. 
 
venkyyyvenkyyy
My mail id is: prasadkv30@gmail.com
Please drop a mail some examples.