[SalesForce] test class error : Method does not exist or incorrect signature

public class MyController {

    @AuraEnabled
    public static Account getAccount(String accId){
        Account acc = [SELECT Id,Name FROM Account WHERE Id =: accId];
        return acc;
    }
}

@isTest
public class MyController{

    @isTest
    static void getAccountTest(){

    MyController a = new MyController()
    Account acc = a.getAccount();
    
    // verify the output
    System.assertEquals(1, acc.size(), 'expecting to find 1 Account');
    
    }
}



//Method does not exist or incorrect signature: void getAccount() from the type MyController
//Method does not exist or incorrect signature: void size() from the type Account

Best Answer

Your getAccount() method is static, meaning you don't use an instance of the object to call it, just the class name + method name like MyController.getAccount().

size() is not a method on SObject, but it is a method on collection types (list, set, and map). Instead of asserting size, since you're only returning 1 record, you could assert that acc is not null.

...though if you wouldn't get an account returned by your query, you'd get a NO_ROWS_FOR_ASSIGNMENT exception before you hit that assert.