ApexSensei

Drills Debugging

Fix a test that checks nothing

A test passes when nothing throws.

Your task

Fix both verifiers so a wrong total, a missing error and a wrong error message each make the test fail.

@IsTest
public class AS_98EF88F18834_PricingTests {
    public static void verifyTotal(List<Decimal> prices, Decimal taxRate, Decimal expected) {
        Decimal result = AS_98EF88F18834_Pricing.total(prices, taxRate);
        System.debug('Total: ' + result);
    }

    public static void verifyRejected(List<Decimal> prices, Decimal taxRate) {
        try {
            AS_98EF88F18834_Pricing.total(prices, taxRate);
        } catch (IllegalArgumentException error) {
            System.debug('Rejected: ' + error.getMessage());
        }
    }

    @IsTest
    static void totalsTwoPrices() {
        verifyTotal(new List<Decimal>{ 10, 20 }, 10, 33.00);
    }

    @IsTest
    static void rejectsANegativePrice() {
        verifyRejected(new List<Decimal>{ -5 }, 10);
    }
}

Requirements

  1. verifiesACorrectTotal should pass
  2. verifiesARoundedTotal should pass
  3. catchesAWrongTotal should pass
  4. verifiesARejection should pass
  5. catchesAMissingRejection should pass
  6. catchesAWrongMessage should pass

Sign in to open this drill