Stockholm syndrome
"Premature optimization is the root of all evil"
Donald Knuth
When testing makes no sense
Miro Svrtan
@msvrtan
When should we write tests?
High cost to fix?
Cost of fixing > cost of testing
When it brings "value"
Value = benefit - cost
Fallacy #1:
It makes my project more expensive
Do you charge for manual testing?
Bugs cost too
Ask for forgiveness, not permission
Fallacy #2:
It takes a lot of time
learning != using
Fallacy #3:
It takes extra time
Manual testing takes time as well
Fallacy #4:
ship PoC to production
Feature lifecycle
Phase 1: Exploration
Phase 2: Modelling/architecture
Phase 3: Development
Phase 4: Production
Fallacy #5:
100% code coverage
class User
{
...
function isAdmin() : bool{
return $this->admin;
}
...
}
Fallacy #6:
writing tests later is OK
class User
{
...
function shouldChargeVat() : bool{
if($this->isCompany()){
return false;
}
return true;
}
...
}
Fallacy #7:
we have "tests"
Fallacy #8:
TDD has something to do with testing
Fallacy #9:
TDD all the way
Easier onboarding
Easier to add new features
class User
{
...
function shouldChargeVat() : bool{
if($this->isCompany()){
return false;
}
return true;
}
...
}
class User
{
...
function shouldChargeVat() : bool{
if(true === $this->isCompany()){
if('SRB' === $this->country){
return true;
}else{
return false;
}
}
return true;
}
...
}
Easier refactoring
class User
{
...
function shouldChargeVat() : bool{
if(true === $this->isCompany()){
if('SRB' === $this->country){
return true;
}else{
return false;
}
}
return true;
}
...
}
class User
{
...
function shouldChargeVat() : bool{
if('SRB' === $this->country){
return true;
}
if(true === $this->isCompany()){
return false;
}
return true;
}
...
}
class User
{
...
function shouldChargeVat() : bool{
if('SRB' === $this->country){
return true;
}
if(true === $this->isCompany()){
return false;
}
return true;
}
...
}
class User
{
...
function shouldChargeVat() : bool{
if(true === $this->isCompany()){
if('SRB' === $this->country){
return true;
}else{
return false;
}
}
return true;
}
...
}
Easier rewriting
Cleaner code
It's hard to test
shitty code
Small app
One off app
Exploration phase
Job security
Thank you!
@msvrtan
Questions?
@msvrtan
\When testing makes no sense
By Miro Svrtan
\When testing makes no sense
PHP Srbija 2018, May 26th 2018
- 1,860