TDD a piccoli passi

Preview:

Citation preview

Ferdinando Santacroce

@JesusWasRasta

TDD a piccoli passi

All’inizio le mie applicazioni le testavo così...

Vediamo un po’ come funziona...

mmm, pensavo fossemeno complicato...

Ho capito, devo usare i mock!

Sì, ma che fatica!

Driven!!

Cos’è TDD?

Scrivi dei test

Scrivi codice fino a farli passare tutti

Fai un po’ di pulizia

The Three Laws of TDD

1. “You aren’t allowed to write any production code until you have written a failing unit test”.

2. “You aren’t allowed to write more of a unit test than is sufficient to fail. And not compiling is failing.”

3. “You aren’t allowed to write more production code than is sufficient to pass the currently failing unit test.”

Ecco cos’è TDD!Write a single test

that fails

Write code to make the test pass

Improve the code base

The Three Laws of TDD1.“You aren’t allowed to write any production code until you have

written a failing unit test”.

2.“You aren’t allowed to write more of a unit test than is sufficient to fail. And not compiling is failing.”

3.“You aren’t allowed to write more production code than is sufficient to pass the currently failing unit test.”

Proviamoci!

See the code on Github: https://github.com/jesuswasrasta/SmallStepsTDD.git

• Nell’algoritmo non v’è espresso il concetto di numero primo• Brainlessness (2 -> n)• I cicli sono una generalizzazione delle if• Passo dei test nuovi senza modificare codice• Se immaginiamo i test come feature, che bello sarebbe aggiungere

funzionalità al nostro software con questa facilità?!• Refactoring: rimuovere duplicazione, rimuovere codice

Cosa si nota?

({}–>nil) no code at all->code that employs nil(nil->constant)(constant->constant+) a simple constant to a more complex constant(constant->scalar) replacing a constant with a variable or an argument(statement->statements) adding more unconditional statements.(unconditional->if) splitting the execution path(scalar->array)(array->container)(statement->recursion)(if->while)(expression->function) replacing an expression with a function or algorithm(variable->assignment) replacing the value of a variable.

Transformations

https://8thlight.com/blog/uncle-bob/2013/05/27/TheTransformationPriorityPremise.html

https://en.wikipedia.org/wiki/Transformation_Priority_Premise

https://www.youtube.com/watch?v=B93QezwTQpI

https://vimeo.com/97516288

https://vimeo.com/60561303

Transformations Priority Premise

Robert C. Martin (Uncle Bob)

@JesusWasRasta

DOmande?

@JesusWasRasta

Recommended