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
PpapasPpapas 

Test Unit frustration

Newbie and frustrated. i would really appreciate a hand here  all the you gurus out there. We the very begginers are still learning.

 

issues for writting a unit test method for the following class. for References, this class came from here

 

public class massAccountUpdateCon {

  private List<Account> accounts;

  public List<Account> getAccounts() {
      return accounts;
  }

  public string keywords {
    get;
    set;
  }

  public PageReference ViewData() {
     
     String query = 'Select id, name, type, ownership, industry, phone, BillingCity, billingCountry FROM account WHERE name LIKE \'' + keywords + '%\'';
   
     accounts = Database.query(query);
                   
     return null;
  }

  public PageReference UpdateRecords() {
    
    update accounts;
    return null;
  }
}

 Thank you so much in advance. 

aballardaballard

The basic form of a test method for this would be

 /* create and insert account record  with name xxxx*/

....

MassAccountUpdateCon con = new MassAccountUpdateCon();

con.keywords = 'xxx';

PageReference next = con.viewData();

System.assert(next == null);

List<Account> data = con.getAccounts();

/* code to verify the right account was retrieved */

...

/* change something in the account */

...

con.UpdateRecords();

/* retrieve the record from the database and verify the change was persisted */

...

 

 

That should give you 100% test coverage.