test-driven development; why you should never code without it

14
TEST DRIVEN DEVELOPMENT A development practice you should not skip

Upload: jad-salhani

Post on 24-Jan-2017

22 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Test-Driven development; why you should never code without it

TEST DRIVEN DEVELOPMENT

A development practice you should not skip

Page 2: Test-Driven development; why you should never code without it

• Computer Science graduate from the American University of Beirut.

• Currently freelancing in software engineering and design

• Focused mainly on Mobile Development using best practices and Agile

methods

• Thriving to be an international speaker in different topics

A BRIEF ABOUT ME

Jad Salhani

Page 3: Test-Driven development; why you should never code without it

3

1. Introduction to TDD

2. Why TDD?

3. TDD vs ADD

4. TDD and Agile

5. Live Demo

OUR PROGRAM

Page 4: Test-Driven development; why you should never code without it

WHAT IS TDD?

• As the name suggests, the tests drive your development

• When developing a product / feature, first the Test is designed

• The test will be based on the product spec, and thus will drive the correct development of the feature

• After the test is written, you keep writing code until it no longer fails

4

Page 5: Test-Driven development; why you should never code without it

For example:

12 class ExampleTest extends TestCase 13 { 14 /** 15 * A basic functional test example. 16 * 17 * @return void 18 */ 19 public function testBasicExample() 20 { 21 $this->visit('/') 22 ->see('Laravel'); 23 } 24 25 public function testAdditionEquation(){ 26 $x = 1; 27 $this->assertEquals(2, $x+$x); 28 } 29 }

Page 6: Test-Driven development; why you should never code without it

• A significant advantage of TDD is that it enables you to take small steps when writing software. 

• It is much easier to find, and then fix, defects if you've written two new lines of code than two thousand

• Especially handy in large-scale projects

• Stable guide for feature development

WHY TDD?“If it's worth building, it's worth testing.

If it's not worth testing, why are you wasting your time working on it?”

Page 7: Test-Driven development; why you should never code without it

TDD VS ADD

• Single Test Suite written at the beginning (“Acceptance Test”)

• Test Suite covers a large product specification, not a single feature / component

• Keep writing code until the test passes

• Move on to next test / End product development

“Begin with the end in mind.” — Stephen R. Covey

Page 8: Test-Driven development; why you should never code without it

19 public function testLogin() 20 { 21 $this->assertTrue(true); 22 } 23 24 public function testRegistration() 25 { 26 $this->assertTrue(true); 27 } 28 29 public function testGetItems() 30 { 31 $this->assertTrue(true); 32 } 33 34 public function testPurchaseItem() 35 { 36 $this->assertTrue(true); 37 } 38 39 public function testViewItemDetail() 40 { 41 $this->assertTrue(true); 42 }

• Write all

product tests

from the start

• Keep writing

code until they

pass

ADD EXAMPLE

Page 9: Test-Driven development; why you should never code without it

• First write the test for the feature

TDD EXAMPLE

19 public function testLogin() 20 { 21 $this->assertTrue(true); 22 }

• Then write the feature

9 class TestController extends Controller 10 { 11 public function loginUser(){ 12 // Some login code in the database 13 } 14 }

• Then run the test

Page 10: Test-Driven development; why you should never code without it

IT FAILS :D

REPEAT

Page 11: Test-Driven development; why you should never code without it

TDD AND AGILE

Page 12: Test-Driven development; why you should never code without it

AGILE MODEL-DRIVEN DEVELOPMENT (AMDD)

• AMDD addresses the agile scaling issues that TDD does not.

• TDD provides detailed specification (tests) whereas AMDD is better for thinking through bigger issues.

• TDD provides concrete evidence that your software works whereas AMDD supports your team, including stakeholders, in working toward a common understanding.

Page 13: Test-Driven development; why you should never code without it

LIVE DEMO

Page 14: Test-Driven development; why you should never code without it

@JadSalhani

github.com/jadsalhani

THANK YOU