21
Test-Driven Development Joshua Lewis @joshilewis

Test-Driven Developmentjoshilewis.github.io/ELEN7045/TDD.pdf · Test-Driven Development Joshua Lewis @joshilewis. What is a test? Unit Tests. Given When I add 2 and 3 Then The sum

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Test-Driven Developmentjoshilewis.github.io/ELEN7045/TDD.pdf · Test-Driven Development Joshua Lewis @joshilewis. What is a test? Unit Tests. Given When I add 2 and 3 Then The sum

Test-DrivenDevelopment

Joshua Lewis

@joshilewis

Page 2: Test-Driven Developmentjoshilewis.github.io/ELEN7045/TDD.pdf · Test-Driven Development Joshua Lewis @joshilewis. What is a test? Unit Tests. Given When I add 2 and 3 Then The sum
Page 3: Test-Driven Developmentjoshilewis.github.io/ELEN7045/TDD.pdf · Test-Driven Development Joshua Lewis @joshilewis. What is a test? Unit Tests. Given When I add 2 and 3 Then The sum

What is a test?

Page 4: Test-Driven Developmentjoshilewis.github.io/ELEN7045/TDD.pdf · Test-Driven Development Joshua Lewis @joshilewis. What is a test? Unit Tests. Given When I add 2 and 3 Then The sum

Unit Tests

Page 5: Test-Driven Developmentjoshilewis.github.io/ELEN7045/TDD.pdf · Test-Driven Development Joshua Lewis @joshilewis. What is a test? Unit Tests. Given When I add 2 and 3 Then The sum

Given

When I add 2 and 3

Then The sum is 5

Page 6: Test-Driven Developmentjoshilewis.github.io/ELEN7045/TDD.pdf · Test-Driven Development Joshua Lewis @joshilewis. What is a test? Unit Tests. Given When I add 2 and 3 Then The sum

Test-Driven Development

Page 7: Test-Driven Developmentjoshilewis.github.io/ELEN7045/TDD.pdf · Test-Driven Development Joshua Lewis @joshilewis. What is a test? Unit Tests. Given When I add 2 and 3 Then The sum

Test-Driven Development

Page 8: Test-Driven Developmentjoshilewis.github.io/ELEN7045/TDD.pdf · Test-Driven Development Joshua Lewis @joshilewis. What is a test? Unit Tests. Given When I add 2 and 3 Then The sum

public void UnitTest(){

int[] inputs = new[] {2, 3};int expectedOutput = 5;

int actualOutput = Add(inputs);

bool passed = actualOutput == expectedOutput;}

Page 9: Test-Driven Developmentjoshilewis.github.io/ELEN7045/TDD.pdf · Test-Driven Development Joshua Lewis @joshilewis. What is a test? Unit Tests. Given When I add 2 and 3 Then The sum

Code Demo

Page 10: Test-Driven Developmentjoshilewis.github.io/ELEN7045/TDD.pdf · Test-Driven Development Joshua Lewis @joshilewis. What is a test? Unit Tests. Given When I add 2 and 3 Then The sum
Page 11: Test-Driven Developmentjoshilewis.github.io/ELEN7045/TDD.pdf · Test-Driven Development Joshua Lewis @joshilewis. What is a test? Unit Tests. Given When I add 2 and 3 Then The sum

Why do TDD?

Page 12: Test-Driven Developmentjoshilewis.github.io/ELEN7045/TDD.pdf · Test-Driven Development Joshua Lewis @joshilewis. What is a test? Unit Tests. Given When I add 2 and 3 Then The sum

Executable Specification

Page 13: Test-Driven Developmentjoshilewis.github.io/ELEN7045/TDD.pdf · Test-Driven Development Joshua Lewis @joshilewis. What is a test? Unit Tests. Given When I add 2 and 3 Then The sum

Living Documentation

Page 14: Test-Driven Developmentjoshilewis.github.io/ELEN7045/TDD.pdf · Test-Driven Development Joshua Lewis @joshilewis. What is a test? Unit Tests. Given When I add 2 and 3 Then The sum

Focus

Page 15: Test-Driven Developmentjoshilewis.github.io/ELEN7045/TDD.pdf · Test-Driven Development Joshua Lewis @joshilewis. What is a test? Unit Tests. Given When I add 2 and 3 Then The sum

TDD is a design tool

Page 16: Test-Driven Developmentjoshilewis.github.io/ELEN7045/TDD.pdf · Test-Driven Development Joshua Lewis @joshilewis. What is a test? Unit Tests. Given When I add 2 and 3 Then The sum

Automated regression testing

Page 17: Test-Driven Developmentjoshilewis.github.io/ELEN7045/TDD.pdf · Test-Driven Development Joshua Lewis @joshilewis. What is a test? Unit Tests. Given When I add 2 and 3 Then The sum

In a single phrase? TDD increases productivity because the hard part of programming is thinking, and TDD makes thinking faster.

- Michael Hill (GeePawHill)

Page 18: Test-Driven Developmentjoshilewis.github.io/ELEN7045/TDD.pdf · Test-Driven Development Joshua Lewis @joshilewis. What is a test? Unit Tests. Given When I add 2 and 3 Then The sum

TDD like satellite navigation

Page 19: Test-Driven Developmentjoshilewis.github.io/ELEN7045/TDD.pdf · Test-Driven Development Joshua Lewis @joshilewis. What is a test? Unit Tests. Given When I add 2 and 3 Then The sum

TDD is NOT about testing

1. Specification2. Living documentation3. Design4. Automated testing

Page 20: Test-Driven Developmentjoshilewis.github.io/ELEN7045/TDD.pdf · Test-Driven Development Joshua Lewis @joshilewis. What is a test? Unit Tests. Given When I add 2 and 3 Then The sum

More Resources

• TDD by Example – Kent Beck• Katas• Code Retreats

Page 21: Test-Driven Developmentjoshilewis.github.io/ELEN7045/TDD.pdf · Test-Driven Development Joshua Lewis @joshilewis. What is a test? Unit Tests. Given When I add 2 and 3 Then The sum

TDD Recap

No code without a failing test

Simplest possible thing

Red Green Refactor