What Should I Test?

Kyle Coberly

kylecoberly.com

  • Educator
  • Business Dork
  • Software Developer

What Needs To Be Tested?

function getInsurancePremiumFactor(age){
    if (age >= 18 && age < 24) {
        return 1.75;
    } else if (age >= 24 && age < 60) {
        return 1;
    } else if (age >= 60) {
        return 1.35;
    }
}

Equivalence Partition Boundaries

18

24

60

Equivalence Partitions

Boundaries

Test Cases

  • 18
  • 23
  • 24
  • 59
  • 60

18

24

60

  • 17?
  • Number.MAX_SAFE_INTEGER?

What do we get?

We can fix this piece of shit...

function getInsurancePremiumFactor(age){
    if (age >= 18 && age < 24) {
        return 1.75;
    } else if (age >= 24 && age < 60) {
        return 1;
    } else if (age >= 60) {
        return 1.35;
    }
}
function getInsurancePremiumFactor(age){
    return insurancePremiumFactors()[getAgeGroup(age)];
}

function getAgeGroup(age){
    return ageGroups().find(ageGroup => {
        age >= ageGroup.minimumAge
            && age < ageGroup.maximumAge
    }).label;
}

function ageGroups(){
    return [{
        minimumAge: 18,
        maximumAge: 24,
        label: "youngAdult"
    },{
        minimumAge: 24,
        maximumAge: 60,
        label: "adult" 
    },{
        minimumAge: 60,
        maximumAge: 100,
        label: "senior"
    }];
}

function insurancePremiumFactors(){
    return {
        youngAdult: 1.75,
        adult: 1,
        senior: 1.35
    };
}

...Confidently!

Other Equivalence Partitions

  • Strings
  • Numbers
  • Collections
  • Domain-Specific

Kyle Coberly

kylecoberly.com

What Should I Test?

By Kyle Coberly

What Should I Test?

Presentation for DenverScript, April 2019

  • 293
Loading comments...

More from Kyle Coberly