pragmatic tdd - luka mužinić · working in a remote team of three software engineers, able to...

40
PRAGMATIC TDD

Upload: others

Post on 26-Jul-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

PRAGMATIC TDD

Page 2: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code reviews. Managing everything from application architecture to infrastructure. Delivering projects that are documented, covered with tests, with automated provisioning of local development virtual machines and production servers.

@lmuzinicLuka Muzinic

HELLO

Page 3: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

ROUGH SCHEDULE09:30 Workshop part 1 11:00 Refreshments 11:15 Workshop part 2 12:45 Lunch

Page 4: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

WORKSHOP RULESASK QUESTIONS IF YOU STILL DO NOT UNDERSTAND, ASK QUESTIONS AGAIN DISCUSS RIGHT NOW, DO NOT WAIT FOR THE “RIGHT MOMENT”

Page 5: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

WHY WE NEED TESTING?

Page 6: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

WHY AM I HERE?

Page 7: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

ARE WE SOFTWARE TESTERS?

Page 8: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

AND YET WE KEEP ON SAYING WE WRITE TESTS…

Page 9: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

WHERE CAN I GET MORE OF THOSE TESTS?

Page 10: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

EXCUSES, EXCUSES

TESTS SLOW US DOWNWE WILL NEVER GET TO 100% CODE COVERAGE WE DO NOT HAVE TIME TO LEARN TESTING, WE’RE TO BUSY SHIPPING CODE

Page 11: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

EXCUSES, EXCUSESTESTS SLOW US DOWN?

Page 12: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

DO YOU OFTEN DO THIS? ~phptest.php

OR THIS http://localhost/test_problem.php

STOP TESTFILEING

Page 13: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

EXCUSES, EXCUSESWE WILL NEVER GET TO 100% CODE COVERAGE

Page 14: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

CODE COVERAGE

Page 15: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

CODE COVERAGE

Page 16: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

CODE COVERAGE

Page 17: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

CODE COVERAGE

Page 18: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

20 > 80

Page 19: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

EXCUSES, EXCUSESWE DO NOT HAVE TIME TO LEARN TESTING, WE’RE TO BUSY SHIPPING CODE

Page 20: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

//@TODO: STANDSTILL

Page 21: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

DON’T BE SCARED OF PHPUNIT*IT IS JUST A CODE RUNNER UNIT, INTEGRATION OR ACCEPTANCE TESTS SMOKE TESTS WEBSITE SCRAPER …

Page 22: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

IS MY CODE WORKING CORRECTLY? WILL MY CODE WORK CORRECTLY? HOW IS MY CODE SUPPOSE TO WORK? IS MY CODE DESIGNED WELL? CAN I REFACTOR MY CODE?

TESTS ANSWER QUESTIONS

Page 23: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

IS MY CODE WORKING CORRECTLY? WILL MY CODE WORK CORRECTLY? HOW IS MY CODE SUPPOSE TO WORK? IS MY CODE DESIGNED WELL? CAN I REFACTOR MY CODE?

TESTS ANSWER QUESTIONS

Page 24: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

IS MY CODE WORKING CORRECTLY? WILL MY CODE WORK CORRECTLY? HOW IS MY CODE SUPPOSE TO WORK? IS MY CODE DESIGNED WELL? CAN I REFACTOR MY CODE?

TESTS ANSWER QUESTIONS

Page 25: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

IS MY CODE WORKING CORRECTLY? WILL MY CODE WORK CORRECTLY? HOW IS MY CODE SUPPOSE TO WORK? IS MY CODE DESIGNED WELL? CAN I REFACTOR MY CODE?

TESTS ANSWER QUESTIONS

Page 26: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

IS MY CODE WORKING CORRECTLY? WILL MY CODE WORK CORRECTLY? HOW IS MY CODE SUPPOSE TO WORK? IS MY CODE DESIGNED WELL? CAN I REFACTOR MY CODE?

TESTS ANSWER QUESTIONS

Page 27: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

IS MY CODE WORKING CORRECTLY? WILL MY CODE WORK CORRECTLY? HOW IS MY CODE SUPPOSE TO WORK? IS MY CODE DESIGNED WELL? CAN I REFACTOR MY CODE?

TESTS ANSWER QUESTIONS

Page 28: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

IS MY CODE WORKING CORRECTLY? WILL MY CODE WORK CORRECTLY? HOW IS MY CODE SUPPOSE TO WORK? IS MY CODE DESIGNED WELL? CAN I REFACTOR MY CODE?

TESTS ANSWER QUESTIONS

Page 29: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

DISCUSSIONIMPLEMENT A FOOTBALL LEAGUE MANAGEMENT APP - We want to display standings table on our website

WHAT IS YOUR BIGGEST CONCERN?

Page 30: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

HOW TO WRITE TESTS?GIVEN WHEN THEN SETUP EXERCISE VERIFY TEARDOWN

Page 31: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

ANATOMY OF PHPUNIT TEST CASEclassTeamTestextendsPHPUnit\Framework\TestCase;{private$team;

publicfunctionsetUp(){$this->team=Team::create('YorkCity');}

publicfunctiontestGetName(){$this->assertEquals('YorkCity',$this->team->getName());}}

Page 32: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

WORKSHOP RULESASK QUESTIONS IF YOU STILL DO NOT UNDERSTAND, ASK QUESTIONS AGAIN DISCUSS RIGHT NOW, DO NOT WAIT FOR THE “RIGHT MOMENT”

Page 33: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code
Page 34: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

Checkout and do composer install https://github.com/lmuzinic/phpyorkshire-pragmatic-tdd

[email protected]:lmuzinic/phpyorkshire-pragmatic-tdd.gitcdphpyorkshire-pragmatic-tddcomposerinstallvendor/bin/phpunit

OK(1test,1assertion)

EXERCISE 0

Page 35: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

EXERCISE 1WRITE A FUNCTIONAL TEST FOR OUR APP - main goal of the test is to show how our code is supposed to work - let us play with with the design, try out how it feels - decide how the output is going to look

Page 36: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

EXERCISE 2RUN TEST - understand why it is failing, look at error messages

DECIDE WHAT IS CRITICAL TO WORK - estimate if you have time to write tests now

WRITE A TEST FOR THAT - create a separate test file as our focus is shifting

GOTO RUN TEST :)

Page 37: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

EXERCISE 3TIE IT ALL TOGETHER - make all tests green

Page 38: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

@lmuzinicLuka Muzinic

QUESTIONS? /r/AMA?

luka.muzinic.net/talks

Page 39: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

HOMEWORKReading list https://www.devmynd.com/blog/five-factor-testing/ https://martinfowler.com/articles/practical-test-pyramid.html https://dev.to/theobendixson/the-problem-that-unit-tests-solve-b2l https://blog.liplex.de/testing-private-and-protected-methods-with-phpunit/

Libraries https://github.com/sebastianbergmann/phpunit https://github.com/phpspec/phpspec https://github.com/Codeception/Codeception https://github.com/phpstan/phpstan https://github.com/infection/infection

STUFF THAT WE MENTIONED IN WORKSHOP AND AFTER IN Q&A

Page 40: PRAGMATIC TDD - Luka Mužinić · Working in a remote team of three software engineers, able to offer outsourcing and consulting services, leadership of development teams and code

KTHXBAIPhotos by Les Anderson, Joshua Earle, Ian Espinosa and Tom Roberts on Unsplash