---
title: "Test Driven Validation Logic with Extract & Override"
url: "https://osherove.com/blog/2012/5/16/test-driven-validation-logic-with-extract-override.md"
canonical: "https://osherove.com/blog/2012/5/16/test-driven-validation-logic-with-extract-override.html"
published: "2012-05-16T09:24:38"
updated: "2012-05-16T09:24:38"
tags: ["Unit Testing"]
author: "Roy Osherove"
description: "In the NerdDinner project, there’s this amazing test (see the bottom, second one). There are so many things wrong here: What is exactly correct about these properties? Many magic values Multiple tests in a single test…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Test Driven Validation Logic with Extract & Override

By Roy Osherove May 16, 2012 In [Unit Testing](https://osherove.com/blog/category/unit-testing)

**Historical article** · Originally published May 16, 2012; technical details may be outdated.

In the NerdDinner project, [there’s this amazing test](http://nerddinner.codeplex.com/SourceControl/changeset/view/70027#874462) (see the bottom, second one).

There are so many things wrong here:

- What is exactly correct about these properties?
- Many magic values
- Multiple tests in a single test
- if it fails,  its hard to find out why

Here’s how I would approach this kind of validation logic:

use Extract and override, with the test setting the flags for all ‘other’ validation functions except the one I’m testing right now. and I’d at least have two tests for each validation logic. This can also be accomplished with multiple classes and an interface, but I find the tests this way are more readable.

## Lessons on this topic

- [Extract And Override With Validation Logic](https://courses.osherove.com/courses/legacy-code-hero/extract-and-override-with-validation-logic/) · Legacy Code Hero
- [Extract And Override Refactoring](https://courses.osherove.com/courses/the-art-of-unit-testing-and-tdd-in-java/extract-and-override-refactoring/) · The Art of Unit Testing and TDD in Java
- [Testing Complex Validation Knowledge using Extract & Override](https://courses.osherove.com/courses/the-art-of-unit-testing-and-tdd-master-class-in-net/testing-complex-validation-knowledge-using-extract-and-override/) · The Art of Unit Testing & TDD Master Class in .NET
- [Best Practices Continued](https://courses.osherove.com/courses/tdd-in-net-in-hebrew/best-practices-continued/) · TDD in .NET in Hebrew
- [Using Extract & Override](https://courses.osherove.com/courses/the-art-of-unit-testing-and-tdd-master-class-in-net/using-extract-and-override/) · The Art of Unit Testing & TDD Master Class in .NET

## More in Unit Testing

[All posts in Unit Testing](https://osherove.com/blog/category/unit-testing)

- Jun 24, 2012

    ### [Video: (part 1) Building a Go Game Engine with TDD and Pair Programming](https://osherove.com/blog/2012/6/25/video-part-1-building-a-go-game-engine-with-tdd-and-pair-pro.html)

- May 16, 2012

    ### [File System Wrappers for Unit Testing in C#](https://osherove.com/blog/2012/5/16/file-system-wrappers-for-unit-testing-in-c.html)

- May 15, 2012

    ### [Test Naming Conventions With Unit of Work](https://osherove.com/blog/2012/5/15/test-naming-conventions-with-unit-of-work.html)

- May 15, 2012

    ### [What does the 'unit' in 'unit test' mean?](https://osherove.com/blog/2012/5/15/what-does-the-unit-in-unit-test-mean.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
