A brief introduction to testing backend code. Examples given in two frameworks in PHP and JavaScript. Written in Serbian language and will be presented in Banja Luka Developers Meetup, March 4 2017.
Many developers are on board with writing unit tests for their code. However a lot of developers don’t test as much as they should because deciding how and what to unit test is harder than deciding to test. Laravel 5 is built with great support for unit testing with PHPUnit but testing applications built using the Model View Controller pattern can prove challenging. This talk will cover ways to design your code to make testing easier and also help you decide what should be unit tested and what should be left to other testing methods.
Many developers are on board with writing unit tests for their code. However a lot of developers don’t test as much as they should because deciding how and what to unit test is harder than deciding to test. Laravel 5 is built with great support for unit testing with PHPUnit but testing applications built using the Model View Controller pattern can prove challenging. This talk will cover ways to design your code to make testing easier and also help you decide what should be unit tested and what should be left to other testing methods.
Backend, MVC, languages and frameworks for BackendDragos Strugar
A presentation for Backend introduction, presented for Prnjavor Technology Enthusiasts in Prnjavor, Bosnia and Herzegovina. It is written in Serbian language and requires a Demo app written in Ruby on Rails.
All the Laravel things: up and running to making $$Joe Ferguson
Laravel 5 has established itself as one of the best PHP rapid application development frameworks. Come learn about all the tools in the Laravel ecosystem designed to save you time and prevent you from writing the boring cruft you have to write for every application. We'll cover getting started with local development, building a basic application, and deploying to production. We'll review how Laravel easily handles vagrant, testing, oauth login services, billing and subscriptions services through Laravel Spark, and deploying your application with services such as Laravel Envoyer and Forge to manage your servers.
Può lo sviluppo di REST API con PHP può diventare un'esperienza davvero gradevole?
Cos'è Laravel, la filosofia che il progetto porta avanti e come costruire API REST complete con uno dei framework più usati negli ultimi anni.
Each month, join us as we highlight and discuss hot topics ranging from the future of higher education to wearable technology, best productivity hacks and secrets to hiring top talent. Upload your SlideShares, and share your expertise with the world!
Not sure what to share on SlideShare?
SlideShares that inform, inspire and educate attract the most views. Beyond that, ideas for what you can upload are limitless. We’ve selected a few popular examples to get your creative juices flowing.
Backend, MVC, languages and frameworks for BackendDragos Strugar
A presentation for Backend introduction, presented for Prnjavor Technology Enthusiasts in Prnjavor, Bosnia and Herzegovina. It is written in Serbian language and requires a Demo app written in Ruby on Rails.
All the Laravel things: up and running to making $$Joe Ferguson
Laravel 5 has established itself as one of the best PHP rapid application development frameworks. Come learn about all the tools in the Laravel ecosystem designed to save you time and prevent you from writing the boring cruft you have to write for every application. We'll cover getting started with local development, building a basic application, and deploying to production. We'll review how Laravel easily handles vagrant, testing, oauth login services, billing and subscriptions services through Laravel Spark, and deploying your application with services such as Laravel Envoyer and Forge to manage your servers.
Può lo sviluppo di REST API con PHP può diventare un'esperienza davvero gradevole?
Cos'è Laravel, la filosofia che il progetto porta avanti e come costruire API REST complete con uno dei framework più usati negli ultimi anni.
Each month, join us as we highlight and discuss hot topics ranging from the future of higher education to wearable technology, best productivity hacks and secrets to hiring top talent. Upload your SlideShares, and share your expertise with the world!
Not sure what to share on SlideShare?
SlideShares that inform, inspire and educate attract the most views. Beyond that, ideas for what you can upload are limitless. We’ve selected a few popular examples to get your creative juices flowing.
2. O MENI
Dragoš Strugar
još u srednjoj
najviše istražujem iOS i backend development
Osvojio Hackathon 2016 Banjaluka
idem na takmičenja inovacija u ZG, BL i NS
3. O ČEMU OVA PREZENTACIJA NIJE
vrste testiranja
potpun tutorijal kako koristiti TDD u Laravelu i Expressu
nije za developere koji su već radili dosta sa TDDom, mada i oni možda nešto nauče
4. PRIJE NEGO ŠTO KAŽEM O ČEMU JE ZAPRAVO OVA PREZENTACIJA..
Šta je Unit testing?
Kako se ta vrsta testiranja razlikuje od ostalih vrsta testova?
Zašto ovo pominjem?
5. O ČEMU JE OVA PREZENTACIJA
UNIT testing, programerski testovi
Automatizovano testiranje
Razumijevanje TDD i Unit testing osnovnih pojmova
Par primjera ovoga u Express.js i Laravel frameworcima
6. PAR PITANJA
Koliko vas misli da je pisanje testova manje ili veće gubljenje vremena?
Koliko vas piše testove u svojim aplikacijama?
Koliko vas to radi TDD/BDD pristupom?
7. SVI TESTIRAJU…
Uđi na browser, posjeti localhost/posts, vidi jesu li svi postovi izlistani
Uđi u konzolu, vidi jesi li uspješno sačuvao/la novi post?
itd..
8. …SAMO NEKI TO AUTOMATIZUJU
napišu kod koji to provjeri za njih
razmislite koliko bi vam to vremena uštedjelo
dodamo novi feature za postove, samo izvrtimo testove da vidimo da li i dalje prolaze
ne moramo tokom noći se pitati da li naš kod radi, ili ima neki bug, samo testiramo prije spavanja, easy..
9. ZA NEKE SLUČAJEVE OVO JE SASVIM DOVOLJNO
recimo, hoćete dodati novi feature u vašu app koji ima baš mnogo slučajeva koji se trebaju provjeriti
vaša app nije prevelika, niste testirali ništa u njoj, ali ovaj feature baš liči na nešto što bi se trebalo
testirati
napišete testove samo za tu funkcionalnost
10. ALI, ZA VEĆINU NIJE..
imate app koja je poprilično velika
ima mnogo koda i mnogo slučajeva koji se trebaju testirati
kad dodate novu funkcionalnost, ona možda sruši neki feature rađen prije..
Full code coverage!
11. ŠTA TESTIRANJEM DOBIJATE?
software koji nema bugova
aplikaciju koja je spremna za produkciju
developersku sreću jer znate da ste odradili
software kako treba
DEVOPS
12. OVDJE STVARI POČINJU DA BUDU ZANIMLJIVE :D
hajdemo zamisliti scenario u kojem bismo napisali prvo testove, a tek onda naš kod?
Čekaj, mali, jesi ti normalan?
Zar to ne bi značilo da naši testovi uvijek prvo padaju?
13. I ODGOVOR JE..
DA!
- pravićemo objekat, čak ako nemamo još napisanu klasu
- zvaćemo metodu koja ne postoji
i kad testove izvršimo, oni trebaju PASTI
14. AKO STE SHVATILI POGREŠNO…
pisanje čitavog test koda prije pisanja jedne linije ”pravog” koda
mart – pisanje testova
april – pisanje koda koji prolazi testiranje
POGREŠNO!
15. HAJDEMO PROMISLITI I NA DRUGI NAČIN
test-driven
znamo smjer u kojem trebamo razvijati našu aplikaciju
u procesu razvoja, znamo TAČNO gdje se pojavljuju greške
RED Green
možda ovaj pristup i nije toliko loš..
18. LARAVEL TDD UVOD
nisam ekspert, ako neko vidi neku grešku u Laravel kodu, neka me slobodno prekine
sve vam je built-in
Hajdemo uzeti primjer pravljenja klase Movie koristeći TDD
19. MOVIE TEST- LARAVEL
- pravimo Movie.php sa običnim <?php class Movie{}
- u tests/ direktorijumu pravimo novi fajl, MovieTest.php
20. IZVRŠAVANJE TESTA - LARAVEL
u rootu projekta kucate phpunit i dodatni argument može biti path do samo jednog testa, ili
direktorijuma u kom se nalazi više testova
Dobićemo Test failed - PHP Fatal Error: ’AppMovie’ not found
Ako u Movie.php dodamo namespace App i izvršimo testove, dobijamo drugi error:
Call to undefined method AppMovie::name()
21. LARAVEL MOVIE CLASS
Ako dodamo metodu name, pomoću public function name(){}
Dobijamo sljedeći error:
Failed asserting that null matches expected ’Star Wars’
22. VRIJEME ZA PITANJA - LARAVEL
kako biste dodali pored imena filma, njegovog režisera (bonus poeni ako znate ko je to)?
zapažate li problem koji će nam se desiti?
setUp method! DRY, guys
public function setUp() {$this->movie = new Movie(‘Star Wars’ , ‘George Lucas’);}
23. LARAVEL - WEB
za request/response je sve built in, pogledajmo primjer
24. PRIMJER NOVI U LARAVELU
Posjetiti home page
$this->visit(‘/’);
Klikni na Click Me link
$this->click(‘Click Me’);
Dodati <a href=”#”>Click Me</a>
Vidi ima li poruka ”Clicked”
$this->see(‘Clicked’);
Prepraviti link da bude href=“/feedback” -> dobijamo 404
Dodati rutu /feeback koja vraća poruku “Clicked”
Vidi da li je trenutni url /feedback
$this->seePageIs(‘feedback’);
25. EXPRESS SADA…
mochajs.org – asynchronous testing
assertion library expect – eror poruke i mnoge druge pogodnosti
supertest – za requeste (GET, POST, …) – ne moramo manualno provjeravati headere, status codove i sl.
26. TEST DRIVE IN EXPRESS
Za ovaj primjer će nam trebati express, mocha, supertest i expect od NPM paketa
Jedan fajl za server i jedan za test
server.js i server.test.js
napravimo u package.json alias
"scripts": {
"test": "mocha **/*.test.js"
},
31. RESURSI ZA UČENJE
Laravel - PHPUnit: https://phpunit.de/
Express – Supertest/Mocha/Expect su na NPM, svi open-source
https://github.com/visionmedia/supertest
Za Laravel preporučujem od Laracasts Testing sekciju
Za Express ne znam takav kurs, ali ima mnogo blog postova..