Salesforce Test Class - Facing - System.NullPointerException: Attempt to de-reference a null object Error while trying to Run Test Class
APEX class
public class NewAccountCreation {
public Account account{get;set;}
public void save(){
Account acc = new Account();
// User enter values in vf page and we are capturing and creating account
acc.name = account.Name;
//acc.address = account.adress;
Insert acc;
}
}
Test Class
@isTest
public class TestNewAccountCreation {
@isTest static void TestNewAccountCreationMethod(){
NewAccountCreation testAccount = new NewAccountCreation ();
Account acc = new Account(Name='TestAcct');
Insert acc;
system.debug(''+acc);
testAccount.save();
System.assert([Select Id From Account].size()==1);
}
}
Error: System.NullPointerException: Attempt to de-reference a null object
StackTrace: Class.NewAccountCreation.save: line 6, column 1 Class.TestNewAccountCreation.TestNewAccountCreationMethod: line 9, column 1