Gil Zilberfeld
Dirty Tests And How To Clean Them
#1about 5 minutes
Why test code is often treated differently
Test code is often neglected because developers don't expect to revisit it and frequently copy-paste existing tests, duplicating code smells.
#2about 1 minute
The developer's job is writing maintainable code
The primary goal of a developer is to write code that works repeatedly, and clean code principles reduce maintenance time.
#3about 7 minutes
Defining clean code as communication with others
Clean code is simple, direct, and written like prose because it is primarily a form of communication between programmers.
#4about 6 minutes
Key attributes of clean and effective tests
Clean tests clearly show their intent, are focused on a single scenario, and use abstraction to separate domain logic from framework details.
#5about 4 minutes
Identifying common code smells in test suites
Common anti-patterns in tests include God classes, unhelpful comments, poor naming, and the use of magic numbers without context.
#6about 5 minutes
Refactoring duplicated code with a common setup
The first refactoring step involves moving duplicated variable initializations from individual tests into a common setup method.
#7about 4 minutes
Improving names and extracting helper methods
Further refactoring involves creating more descriptive test names, extracting repeated API call logic into a helper method, and using production constants to build robust URLs.
#8about 4 minutes
Using the builder pattern for test data setup
The Builder pattern simplifies the creation of complex data objects for tests by handling default values and making unique parameters more visible.
#9about 2 minutes
Separating concerns with an API call wrapper
Create an abstraction layer like an API call wrapper to separate low-level HTTP and JSON logic from the high-level domain language of the tests.
#10about 5 minutes
Signaling intent with descriptive constant names
Use named constants like `ANY_NUMBER` versus specific values to signal to the reader which test inputs are arbitrary and which are significant for the scenario.
#11about 3 minutes
Discussing hierarchical test classes and organization
Hierarchical test classes can be useful, but it is often better to favor composition over inheritance to avoid creating brittle test structures that are hard to change.
#12about 8 minutes
Career advice on starting in testing and consulting
Starting a career in testing provides a valuable mindset shift for building quality software, and self-employment offers flexibility but requires stepping out of one's comfort zone.
Related jobs
Jobs that call for the skills explored in this talk.
MARKT-PILOT GmbH
Stuttgart, Germany
Remote
€75-90K
Senior
Java
TypeScript
+1
Matching moments
03:16 MIN
Improving the developer feedback loop with specialized tools
Developer Time Is Valuable - Use the Right Tools - Kilian Valkhof
04:09 MIN
The emerging market for fixing AI-generated code
Devs vs. Marketers, COBOL and Copilot, Make Live Coding Easy and more - The Best of LIVE 2025 - Part 3
03:58 MIN
Making accessibility tooling actionable and encouraging
Developer Time Is Valuable - Use the Right Tools - Kilian Valkhof
03:31 MIN
The value of progressive enhancement and semantic HTML
WeAreDevelopers LIVE – You Don’t Need JavaScript, Modern CSS and More
02:55 MIN
Why developers often undervalue their time and paid tools
Developer Time Is Valuable - Use the Right Tools - Kilian Valkhof
02:48 MIN
Building trust through honest developer advocacy
Devs vs. Marketers, COBOL and Copilot, Make Live Coding Easy and more - The Best of LIVE 2025 - Part 3
03:45 MIN
Preventing exposed API keys in AI-assisted development
Slopquatting, API Keys, Fun with Fonts, Recruiters vs AI and more - The Best of LIVE 2025 - Part 2
05:55 MIN
The security risks of AI-generated code and slopsquatting
Slopquatting, API Keys, Fun with Fonts, Recruiters vs AI and more - The Best of LIVE 2025 - Part 2
Featured Partners
Related Videos
Write tests you love, not hate
Jens Happe
I will have to refactor ! And now ? Refactoring Techniques in Java
Kamila Santos
How Unit Testing Saved My Career
Annelore Egger
The Clean as You Code Imperative
Olivier Gaudin
Why you must use TDD now!
Alex Banul
How to TDD in legacy code
Gil Zilberfeld
Keep your code refactorable
Gerrit Stapper
How not to test
Golo Roden
Related Articles
View all articles



From learning to earning
Jobs that call for the skills explored in this talk.

Eltemate
Amsterdam, Netherlands
Intermediate
Senior
TypeScript
Automated Testing
Continuous Integration

Power Plus Communications
Mannheim, Germany
Intermediate
Senior
Python
Unit Testing
Automated Testing

Code Healers LLC
Hinesville, United States of America
Remote
€30-40K
Intermediate
Senior
.NET
React
JavaScript
+2

Market Lavington
Market Lavington, United Kingdom
Java
JUnit
Spring
Jenkins
Selenium
+2

Epam Systems, Inc.
Zürich, Switzerland
Selenium
Cucumber
TypeScript
Tricentis Tosca Testsuite




Test Driven Solutions
Edinburgh, United Kingdom
Intermediate
Java
MySQL
NoSQL
Scrum
Jenkins
+4