SlideShare uma empresa Scribd logo
1 de 24
Baixar para ler offline
Plan na dziś
1.Powtórzenie
2.Red
3.Green
4.Refactor
3 PRAWA TDD wg UNCLE BOBA
1.Nie pisz żadnego kodu produkcyjnego jeśli nie
ma nieprzechodzącego testu
2.Pisz tylko tyle testu, aby zademonstrować, że
nie przechodzi
3.Pisz tylko tyle kodu produkcyjnego, aby test
przeszedł
CYKL TDD
RED
GREEN
REFACTOR
spraw aby
test
przechodził
napisz
nieprzechodzący
test
refaktoryzuj
RED
Clock clock = new Clock();
clock.set(6, 15);
wait.minutes(5);
assertClockAt(6, 20);
RED
Clock clock = new Clock();
clock.set(6, 15);
wait.minutes(5);
assertClockAt(6, 20);
✔MYŚLENIE
✔PROJEKTOWANIE
FEEDBACK
✔JAKOŚĆ PROJEKTU
✔TESTOWALNOŚĆ
✔JAKOŚĆ TESTU
LISTA TESTÓW
● sprzedaż jednego produktu
● brak kodu kreskowego
● pusty kod kreskowy
● ...
● zła nazwa „Storage”
● duplikacja w CatalogItem
DOSTOSUJ SZYBKOŚĆ
CO SIĘ STANIE?
WIELKOŚĆ KROKU
BIEGŁOŚĆ W TDD
ZŁOŻONOŚĆ PROBLEMU
ZNAJOMOŚĆ DZIEDZINY
TESTY JEDNOSTKOWE
● Muszą uruchamiać się szybko
● Test nie jest testem jednostkowym jeśli:
● komunikuje się z bazą danych
● korzysta z sieci
● dotyka systemu plików
● musisz coś zmienić w środowisku aby go
uruchomić
Michael C. Feathers, Working Effectively with Legacy Code
DOBRE TESTY JEDNOSTKOWE
● F ast
● I solated
● R epeatable
● S elf-validating
● T imely
● tysiące / sekundę
● wskazuje błąd
● nieważna kolejność ani czas
● brak ręcznego sprawdzania
● napisane przed kodem
GREEN
Clock clock = new Clock();
clock.set(6, 15);
wait.minutes(5);
assertClockAt(6, 20);
class Clock
{
…
}
?
?
?
class Clock
{
…
}
class Clock
{
…
}
GREEN
Clock clock = new Clock();
clock.set(6, 15);
wait.minutes(5);
assertClockAt(6, 20);
class Clock
{
…
}
?
?
?
class Clock
{
…
}
class Clock
{
…
}
FEEDBACK
✔ POPRAWNOŚĆ
✔ REGRESJA
✔ WIELKOŚĆ KROKU
FAKE IT
OBVIOUS
IMPLEMENT
ATION
TRIANGULATE
FAKE IT
public int getSize {
return 12;
}
OBVIOUS
IMPLEMENT
ATION
public static int[] generatePrimes(int maxValue) {
if (maxValue >= 2) // the only valid case
{
// declarations
int s = maxValue + 1; // size of array
boolean[] f = new boolean[s];
int i;
// initialize array to true.
for (i = 0; i < s; i++)
f[i] = true;
// get rid of known non-primes
f[0] = f[1] = false;
// sieve
int j;
for (i = 2; i < Math.sqrt(s) + 1; i++) {
if (f[i]) // if i is uncrossed, cross its multiples.
{
for (j = 2 * i; j < s; j += i)
f[j] = false; // multiple is not prime
}
}
// how many primes are there?
int count = 0;
for (i = 0; i < s; i++) {
if (f[i])
count++; // bump count.
}
int[] primes = new int[count];
// move the primes into the result
for (i = 0, j = 0; i < s; i++) {
if (f[i]) // if prime
primes[j++] = i;
}
return primes; // return the primes
} else
// maxValue < 2
return new int[0]; // return null array if bad input.
}
TRIANGULATE
integer7ShouldNotBeDivisibleBy3
public boolean isDivisible(int dividend, int divisor {
return dividend % divisor == 0;
}
integer6ShouldBeDivisibleBy3
public boolean isDivisible(int dividend, int divisor {
return true;
}
REFACTOR
Clock clock = new Clock();
clock.set(6, 15);
wait.minutes(5);
assertClockAt(6, 20);
?
?
?
REFACTOR
Clock clock = new Clock();
clock.set(6, 15);
wait.minutes(5);
assertClockAt(6, 20);
?
?
?
✔ PROJEKT (ŁATWOŚĆ)
✔ TESTY (BEZPIECZEŃSTWO)
FEEDBACK
REFAKTORYZACJA
ZMIANA
WEWNĘTRZNEJ STRUKTURY
KODU BEZ ZMIANY
ZEWNĘTRZNEGO
ZACHOWANIA
POZIOMY REFAKTORYZACJI
double
basePrice
=
anOrder.basePrice();
return
(basePrice
>
1000);
return (anOrder.basePrice() > 1000);
2 NAJWAŻNIEJSZE ZASADY
REMOVE
DUPLICATION
(DRY)
IMPROVE
NAMES
GREEN
REFACTOR
UTRZYMUJ
TESTY
ZIELONE
[7,8,9] http://www.flickr.com/photos/thofik/3920097812
[14,16] http://www.flickr.com/photos/29225114@N08/2778223048/
[14] http://www.flickr.com/photos/j-pocztarski/4226650088/
[22] http://www.flickr.com/photos/macca/204553997
[22] http://www.courier-journal.com/blogs/vel05/uploaded_images/baby-names-720609.jpg
DZIĘKUJĘ
Zdjęcia:

Mais conteúdo relacionado

Destaque

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Destaque (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

02 - Mechanika TDD