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
Sabrina Oliveira 3Sabrina Oliveira 3 

How can I get a good coverage with my class test?

My class:
public class getAccount {
	@AuraEnabled 
    public static Account getAcct(Id accountId){
        return (Account) Database.query( ' SELECT Name, Observations__c FROM Account WHERE Id =: accountId LIMIT 1 ' )[0];
    }

    @AuraEnabled 
    public static Account saveAcct(Account act){
        upsert act;
        return act;
    }  
}

My class test:
public class getAccountTest {
    
    @TestSetup
    static void dataSetup(){
        Account acc = new Account();
        acc.Name = 'Testing';
        acc.Status__c = 'Active';
        acc.Observations__c = 'teste';
        insert acc;
    }
    
    static testmethod void getAccountTestMethod() {
            Test.StartTest();
            getAccount instancevar = new getAccount();
            Test.StopTest(); 
        
        	List<Account> accResult = [SELECT Id FROM Account WHERE Name = 'Testing' ];
        
        	System.assertEquals(1, accResult.size() , 'Not created account');
	}

}

But I'm receiving 0% of coverage. What am I missing?
Best Answer chosen by Sabrina Oliveira 3
CharuDuttCharuDutt
Hii Sabrina
Try Below Test Class 100% Coverage
@isTest
public class getAccountTest {
    @isTest
    public static void dataSetup(){
        Account acc = new Account();
        acc.Name = 'Testing';
       acc.Status__c = 'Active';
        acc.Observations__c = 'teste';
        insert acc;
        Test.StartTest();
            //ClassName.Method Name();
            getAccount.getAcct(acc.Id);
        getAccount.saveAcct(acc);
            Test.StopTest(); 
        
        	List<Account> accResult = [SELECT Id FROM Account WHERE Name = 'Testing' ];
        
        	System.assertEquals(1, accResult.size() , 'Not created account');
	
    }
}
Please Mark It As Best Answer If It Helps
Thank You!

All Answers

CharuDuttCharuDutt
Hii Sabrina
Try Below Test Class 100% Coverage
@isTest
public class getAccountTest {
    @isTest
    public static void dataSetup(){
        Account acc = new Account();
        acc.Name = 'Testing';
       acc.Status__c = 'Active';
        acc.Observations__c = 'teste';
        insert acc;
        Test.StartTest();
            //ClassName.Method Name();
            getAccount.getAcct(acc.Id);
        getAccount.saveAcct(acc);
            Test.StopTest(); 
        
        	List<Account> accResult = [SELECT Id FROM Account WHERE Name = 'Testing' ];
        
        	System.assertEquals(1, accResult.size() , 'Not created account');
	
    }
}
Please Mark It As Best Answer If It Helps
Thank You!
This was selected as the best answer
Sabrina Oliveira 3Sabrina Oliveira 3
Hi, CharuDutt!

Thank you, it helped me a lot!