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
HARI KRISHNAHARI KRISHNA 

Help me to resolve Unit Test

This is the snap shot for below issue
----------------This is the Controller Class Where i am facing Problem.---------------------
public class RerenderEx {

    public contact con{set;get;}
    public boolean Abool{set;get;}
    public boolean Bbool{set;get;}    

    public RerenderEx()
    {
        con=new contact();
        Abool=false;
        Bbool=false;
    }
    public void saveNew() {
        insert con;
        con.clear();//con=new contact();
    }

    public void saveSec() {
        insert con;
        Abool=true;
    }
    
    public void EditSec() {
        Abool=false;
        Bbool=true;
    }
    
     public void updateSec() {
        update con;
    }

}
------------------------------This is the Test Class which is unable to Cover above Class .Its covering only 50%----------
@isTest
public class RerenderEx_TC
{
    static testMethod void testMthd()
    {
     boolean Abool=false;
     boolean Bbool=false;    
    RerenderEx r=new RerenderEx();
     contact con=new contact(lastname='xxx');
    r.saveNew();
     insert con;
     con.lastname='xyy';
     update con;
      r.saveSec();
     r.EditSec();
     r.updateSec();
     }
}
 
Best Answer chosen by HARI KRISHNA
ManjunathManjunath
Hi,

You have created a test record in your test class, but you are inserting the controllers records.

The test cls should be like this
 
@isTest
public class RerenderEx_TC
{
    static testMethod void testMthd()
    {
		boolean Abool=false;
		boolean Bbool=false;    
		RerenderEx r=new RerenderEx();
		r.con=new contact(lastname='xxx');
		r.saveNew();
		r.con.lastname='xyy';
		r.saveSec();
		r.EditSec();
		r.updateSec();
     }
}

I dont know the logic implemented, But this should do it.

Regards,
MCS