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
div ninediv nine 

Can any body help me writing test class for this code

public class apex {
public account acc {get;set;}

public apex(){

account acc = [select name from account limit 1];

}
}
Raj VakatiRaj Vakati
@istest()
public class apexTest
{
  private static testmethod void TestCase()
 {


 Account obj = new Account(Name ='Test');
 insert obj;

	apex a = new apex();
	

	 }
 }

 
div ninediv nine
Thanks!!
div ninediv nine
But this code has only 66% code coverage:
User-added image
Raj VakatiRaj Vakati
@istest()
public class apexTest
{
  private static testmethod void TestCase()
 {


 Account obj = new Account(Name ='Test');
 insert obj;

	apex a = new apex();
	
Account tempacc = a.acc ;


	 }
 }

 
Raj VakatiRaj Vakati
I got 100 % with below code
 
@istest
public class apexTest
{
    private static testmethod void TestCase()
    {
        Account obj = new Account(Name ='Test');
        insert obj;
        apex a = new apex();
        Account acc =a.acc ; 
    }
}

User-added image
div ninediv nine
I also got it thank you