Test Drive Dirven Driver HAHAahhaha.pptx

findwaytocom 8 views 28 slides Mar 05, 2025
Slide 1
Slide 1 of 28
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28

About This Presentation

Test Drive Dirven


Slide Content

What is TDD Add a little test Run all tests and fail Make a little change Run the tests and succeed Refactor to remove duplication From Kent Beck Author of “Test Driven Development By Example” and xUnit

TDD TDD là cái gì?

Unit Test

Good Programer Test Minimize programmer waiting. Run reliably. Predict deployability. Respond to behavior changes. Not respond to structure changes. Be cheap to write. Be cheap to read. Be cheap to change

Unit test value proposition Has a high chance of catching a regression bug. Has a low chance of producing a false positive. Provides fast feedback. From Vladimir Khorikov

Style Of Unit Test Functional style

Style Of Unit Test State verification

Style Of Unit Test Collaboration v erification

SOU examples

When to use Collaboration Verification Style? Just 1 Collaboration Test verify the order, times method invoked, and the parameter pass to method Many function style test to verify output/state of sut

What should be unit tested? Common code used in many modules Code that frequently changed Code that frequently causes bugs

What shouldn’t be unit tested? External libraries or frameworks Trivial code (such as getter/setter) Code that works only with UI Code that only access Database Private methods

Smelled Unit Test It calls Database It communicate through networks It read the file system It can’t run parallel with others It depend on environment variable It test private method It test method works only with UI It need complicated setup with a lot of mocking It complicated compare with code (sometime event more)

Code coverage "In computer science the Pareto principle can be applied to optimization efforts. [17] For example, Microsoft noted that by fixing the top 20% of the most-reported bugs, 80% of the related errors and crashes in a given system would be eliminated. [18] Lowell Arthur expressed that "20% of the code has 80% of the errors. Find them, fix them!" [19] It was also discovered that in general the 80% of a certain piece of software can be written in 20% of the total allocated time. Conversely, the hardest 20% of the code takes 80% of the time. This factor is usually a part of COCOMO estimating for software coding. WordPerfect and other software developers identify what customers want most of the time and how they want to do it: the 80/20 rule (people use 20% of a program’s functions 80% of the time). Software developers work to make high-use functions as simple and automatic and inevitable as possible" Code coverage should be used as a guidance to where we need more test than a standard or KPI

Refactoring Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior. From Martin Fowler => Refactor is not optimization ? => Refactor is not extension but refactoring to make extension easier

Refactoring knowledges Refactoring Improving the Design of Existing Code Refactoring Technique Design Pattern SOLID principles .

Refactoring tool Manually rename a function that used 200 times throughout the code base? Tool encourages developers refactoring Resharper is the best but costly (300$/dev/year) Roslynator is free one that closest to Resharper (but still very far behind)

People’s racket of refactoring: it needs more time Code access limitation Git Branching Model Not enough test Legacy code Database Refactoring's Obstacles

Refactoring is an investment to improve the internal quality of code that Make it easier and faster to do the current work Make it easier and faster to modify / extend in the future Developer freely do refactor every day to help him do the current task faster, easier - Make change easy then make easy change (Kent Beck) Developer talk to stakeholders for refactor that invest for the future to get approval If you see refactor make you work slower , stop it. If something is messy but working, let it that way, don’t refactor unless you need to update for business Refactoring practice

TDD with Legacy code Legacy code? The main thing that distinguishes legacy code from non-legacy code is a lack of comprehensive tests From Micheal Feather Author of Working effectively with the legacy code TDD with Legacy code = Test Driven Refactoring

Top-down

Bottom-up

Find Something that should be refactored

Extract Method

Refactor to pure function

Courses Refactoring course Unit Test Course TDD course And more on Pluralsight, Udemy...

References https://enterprisecraftsmanship.com/ Programer Test Principles https://martinfowler.com/bliki/UnitTest.html Test Driven Development By Example Refactoring Improving the Design of existing code Working Effectively with the legacy code

Open Discussion
Tags