9
TDD, Unit Testing, & Smart Unit Tests Jeremy Clark www.jeremybytes.com

TDD, Unit Testing, & Smart Unit Testsjeremybytes.com/Downloads/Slides-TDD.pdf · TDD, Unit Testing, & Smart Unit Tests Jeremy Clark

  • Upload
    ngodung

  • View
    226

  • Download
    1

Embed Size (px)

Citation preview

TDD, Unit Testing, & Smart Unit Tests

Jeremy Clarkwww.jeremybytes.com

TDD Description

• Failing unit test

Red

• Just enough code to pass the test

Green

• Adjust implementation

Refactor

© Jeremy Clark 2015

Conway’s Game of Life

Live Cell -> Dead

• Any live cell with fewer than two live neighbors dies, as if caused by under-population.

Live Cell -> Alive

• Any live cell with two or three live neighbors lives on to the next generation.

Live Cell -> Dead

• Any live cell with more than three live neighbors dies, as if by overcrowding.

Dead Cell -> Alive

• Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.

© Jeremy Clark 2015

Examples

© Jeremy Clark 2015

Dies (Loneliness)

Lives (Reproduction)

Lives (Happy)

Dies (Overcrowding)

Smart Unit Tests

What is Smart Unit Tests?

• Available in Visual Studio 2015 (Preview)

• Generates tests based on existing code

• Follows all code paths to create 100% coverage

• Shows what the code *actually* does not what it is *expected* to do

Caveats

• Still in Preview

• Has some limitations

© Jeremy Clark 2015

Sample Code

© Jeremy Clark 2015

Code Path

Cell State (Alive/Dead)

Alive

Neighbors< 2

Dead

Neighbors>= 2 && <= 3

Alive

Neighbors> 3

Dead

Dead

Neighbors= 3

Alive

Neighbors!=3

Dead

© Jeremy Clark 2015

Smart Unit Tests Code Path

Cell State (Alive/Dead)

Alive

Neighbors< 2

Dead

Neighbors>= 2 && <= 3

Alive

Dead

Neighbors= 3

Alive

Neighbors!=3

Dead

Cell State= 2

Neighbors= 0

Cell State = 2

© Jeremy Clark 2015

Thank You

Jeremy Clark

[email protected]

• www.jeremybytes.com

© Jeremy Clark 2015