Gil Zilberfeld

Dirty Tests And How To Clean Them

Are your tests a maintenance nightmare? Learn to apply clean code principles and transform them into a valuable, readable asset.

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.

d

Saby Company
Delebio, Italy

Junior

asasd

Expire

Remote
Junior

test

Milly
Vienna, Austria

Intermediate

Featured Partners

Related Articles

View all articles
AD
Andrew Dego
Test article 1
Test article Content Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pel...
Test article 1
DC
Daniel Cranney
The real reason we document our code
The world of software development moves fast. Technology is constantly changing, as are the tools we use with it, and even the role of a programmer is itself constantly in flux. However, some aspects of software engineering are so foundational that w...
The real reason we document our code
AL
Anna Lysiuk
10 Coding Habits That Make You a Bad Programmer
Computer programming is crucial in today’s automated world. It makes it possible for people to interact with machines more efficiently and accurately. Computer programmers use a variety of computer languages to create codes that make it possible for ...
10 Coding Habits That Make You a Bad Programmer

From learning to earning

Jobs that call for the skills explored in this talk.

Test Engineer

Test Engineer

Acrolinx
Berlin, Germany

Senior
Java
Linux
Maven
PostgreSQL
Manual Testing
+2
Code cleaner

Code cleaner

Cleanup Services
Rome, Italy

Remote
45-50K
Intermediate
PHP
JavaScript