ApexSensei

Drills Unit testing

Check partial DML results

Database.insert(rows, false) returns one SaveResult per row.

Your task

Finish the insert helper and a verifier that fails unless row 1 saved and row 2 failed because Name is missing.

@IsTest
public class AS_A3060F564EF1_SaveResultTests {
    public static List<Database.SaveResult> insertMixed(String token) {
        List<Account> records = new List<Account>{
            new Account(Name = 'AS Valid ' + token),
            new Account()
        };
        return new List<Database.SaveResult>();
    }

    public static Boolean verifyMixed(List<Database.SaveResult> results) {
        return false;
    }

    @IsTest
    static void mixedInsert() {
        Assert.isTrue(verifyMixed(insertMixed('visible')));
    }
}

Requirements

  1. keepsValidRecord should pass
  2. reportsRequiredField should pass
  3. verifiesRealOutcome should pass
  4. catchesSecondRowSaved should pass
  5. catchesWrongErrorCode should pass

Sign in to open this drill