Mutation

Testing

Zvonimir Spajic

Software?

<?php

class Bartender {

    // ...

	public function serveDrink(Customer $customer) {
    	
        if ($customer->age < 18){
        	throw \Exception('Not allowed to drink');
        }
        
        // ...
    }

}
<?php

class Bartender {

    // ...

	public function serveDrink(Customer $customer) {
    	
        if ($customer->age > 18){
        	throw \Exception('Not allowed to drink');
        }
        
        // ...
    }

}
<?php

class Bartender {

    // ...

	public function serveDrink(Customer $customer) {
    	
        if ($customer->age > 18){
        	throw \Exception('Not allowed to drink');
        }
        
        // ...
    }

}
<?php

class BartenderTest {

    // ...

	public function test_it_does_not_serve_customer_under_age_18() {
    	
        $customer = new Customer(10);
        $bartender = new Bartender();
        
        
        $this->exceptException(\Exception::class);
        
        $bartender->serve($customer);
    }

}

Are your test really testing?

<?php

class BartenderTest {

    // ...

	public function test_it_does_not_serve_customer_under_age_18() {
    	
        $customer = new Customer(18);
        $bartender = new Bartender();
        
        
        $this->exceptException(\Exception::class);
        
        $bartender->serve($customer);
    }

}
<?php

public function hasErrors(): bool
{
    return count($this->errors) > 0;
}

WIP - Mutation Testing

By konrad 126

WIP - Mutation Testing

  • 633