<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-to-use-differential-testing-during-a-legacy-migration-epakjbafd" -->

---
title: How to Use Differential Testing During a Legacy Migration
description: A detailed methodology for using differential testing to de-risk legacy system migrations: running old and new implementations against the same inputs and...
canonical: https://daily.dev/posts/how-to-use-differential-testing-during-a-legacy-migration-epakjbafd
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How to Use Differential Testing During a Legacy Migration | daily.dev
og:description: A detailed methodology for using differential testing to de-risk legacy system migrations: running old and new implementations against the same inputs and...
og:url: https://daily.dev/posts/how-to-use-differential-testing-during-a-legacy-migration-epakjbafd
og:image: https://api.daily.dev/og/posts/EpakjbAFD.png
og:image:alt: How to Use Differential Testing During a Legacy Migration
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Use Differential Testing During a Legacy Migration

**[freeCodeCamp](https://daily.dev/sources/freecodecamp)** · 22 min read · 1 upvotes · 0 comments

## Summary

A detailed methodology for using differential testing to de-risk legacy system migrations: running old and new implementations against the same inputs and comparing outputs to surface behavioral divergence before cutover. Covers normalizing outputs, handling nondeterministic values like timestamps and IDs, comparing errors and side effects, applying tolerances, building a reusable test harness, generating cases from production data, classifying mismatches, safely using shadow traffic, measuring divergence rates, and using AI to triage (but not decide) differences. Examples use TypeScript and Vitest, though the approach generalizes across languages.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.freecodecamp.org/news/differential-testing-legacy-migration>

## Questions this post answers

### How do I handle timestamps and generated IDs when comparing outputs during a differential test for a legacy migration?

Normalize them out of the comparison or control them via dependency injection. Move nondeterministic sources like the current time or ID generation behind an interface (a Clock or IdGenerator) and inject the same fixed value into both the legacy and new implementations during tests, removing time and IDs as sources of meaningless divergence. If injection isn't practical, exclude those fields in a normalization step before comparing outputs.

_Migrating a legacy system? Track testing techniques like this one on daily.dev as you plan the cutover._

### How should I compare error handling between old and new implementations during a migration?

Wrap both implementations' calls in a helper that converts thrown exceptions and successful returns into the same comparable shape, such as an object with a type field of 'success' or 'error'. This lets a test assert that error type matches between legacy and new code even when one throws and the other might silently return null, exposing contract changes like a missing customer producing an exception in the old system but a null return in the new one.

_Comparing error contracts across implementations is easier to reason about with resources like this on daily.dev._

### How do I safely use shadow traffic to compare a new implementation against a legacy system in production without causing duplicate side effects?

Mirror real production requests to the new system while still returning the legacy response to the user, but replace any destructive external calls (payments, emails, inventory updates) with recording adapters that capture what would have been sent instead of executing it for real. This lets you compare the shadow system's intended behavior against the legacy system's actual side effects without risking duplicate charges or external actions.

_Planning a shadow-traffic rollout for a migration is safer with practical guidance like this on daily.dev._

## Similar posts on daily.dev

- [How to Migrate a Legacy Monolith Incrementally Without a Big-Bang Rewrite](https://daily.dev/posts/how-to-migrate-a-legacy-monolith-incrementally-without-a-big-bang-rewrite-kvyh32xa2) · freeCodeCamp · 0 upvotes · 0 comments
- [A Testing Strategy for Legacy Modernisation \| Insights](https://daily.dev/posts/a-testing-strategy-for-legacy-modernisation-insights-bckoasyqj) · Dev Genius · 0 upvotes · 0 comments
- [Master Complex Data Migrations with Snapshot Testing](https://daily.dev/posts/master-complex-data-migrations-with-snapshot-testing-6bil54f0b) · Atomic Spin · 0 upvotes · 0 comments
- [Migration Series — Lesson 5: The Final Gate: Proving Trust with Rigorous, Automated Validation](https://daily.dev/posts/migration-series-lesson-5-the-final-gate-proving-trust-with-rigorous-automated-validation-tmofuir4s) · Snowflake Community · 0 upvotes · 0 comments
- [How to Build Characterization Tests Before Refactoring Legacy Code](https://daily.dev/posts/how-to-build-characterization-tests-before-refactoring-legacy-code-5jwk11sf3) · freeCodeCamp · 1 upvotes · 1 comments

---

Tags: [#testing](https://daily.dev/tags/testing), [#typescript](https://daily.dev/tags/typescript), [#vitest](https://daily.dev/tags/vitest)

[View this post on daily.dev](https://daily.dev/posts/how-to-use-differential-testing-during-a-legacy-migration-epakjbafd)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How to Use Differential Testing During a Legacy Migration","url":"https://daily.dev/posts/how-to-use-differential-testing-during-a-legacy-migration-epakjbafd","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-to-use-differential-testing-during-a-legacy-migration-epakjbafd"},"datePublished":"2026-09-14T21:08:43.284Z","dateModified":"2026-09-14T22:18:21.013Z","description":"A detailed methodology for using differential testing to de-risk legacy system migrations: running old and new implementations against the same inputs and...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/cea56d688dbd23d5c6ca26f9e4897fc4?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/cea56d688dbd23d5c6ca26f9e4897fc4?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"freeCodeCamp","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"freeCodeCamp","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1628412854/logos/freecodecamp","url":"https://daily.dev/sources/freecodecamp"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/how-to-use-differential-testing-during-a-legacy-migration-epakjbafd","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"testing,typescript,vitest","timeRequired":"PT22M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"freeCodeCamp","item":"https://daily.dev/sources/freecodecamp"},{"@type":"ListItem","position":3,"name":"How to Use Differential Testing During a Legacy Migration"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/how-to-use-differential-testing-during-a-legacy-migration-epakjbafd#faq","mainEntity":[{"@type":"Question","name":"How do I handle timestamps and generated IDs when comparing outputs during a differential test for a legacy migration?","acceptedAnswer":{"@type":"Answer","text":"Normalize them out of the comparison or control them via dependency injection. Move nondeterministic sources like the current time or ID generation behind an interface (a Clock or IdGenerator) and inject the same fixed value into both the legacy and new implementations during tests, removing time and IDs as sources of meaningless divergence. If injection isn't practical, exclude those fields in a normalization step before comparing outputs. Migrating a legacy system? Track testing techniques like this one on daily.dev as you plan the cutover."}},{"@type":"Question","name":"How should I compare error handling between old and new implementations during a migration?","acceptedAnswer":{"@type":"Answer","text":"Wrap both implementations' calls in a helper that converts thrown exceptions and successful returns into the same comparable shape, such as an object with a type field of 'success' or 'error'. This lets a test assert that error type matches between legacy and new code even when one throws and the other might silently return null, exposing contract changes like a missing customer producing an exception in the old system but a null return in the new one. Comparing error contracts across implementations is easier to reason about with resources like this on daily.dev."}},{"@type":"Question","name":"How do I safely use shadow traffic to compare a new implementation against a legacy system in production without causing duplicate side effects?","acceptedAnswer":{"@type":"Answer","text":"Mirror real production requests to the new system while still returning the legacy response to the user, but replace any destructive external calls (payments, emails, inventory updates) with recording adapters that capture what would have been sent instead of executing it for real. This lets you compare the shadow system's intended behavior against the legacy system's actual side effects without risking duplicate charges or external actions. Planning a shadow-traffic rollout for a migration is safer with practical guidance like this on daily.dev."}}]}
```

