# Proper Unit Tests

- Speaker: [Omer Lachish-Rauchwerger](/wiki/speakers/omer-lachish-rauchwerger.md)
- Event: [Reversim Summit 2014](/wiki/years/2014.md)
- Video: https://www.youtube.com/watch?v=kl0BOJ8xu3U
- Transcript: [/transcripts/2014/54-kl0BOJ8xu3U.md](/transcripts/2014/54-kl0BOJ8xu3U.md)
- Language: Hebrew · Type: talk · Level: intermediate
- Topics: [Software Engineering](/wiki/topics/software-engineering.md), [Testing](/wiki/topics/testing.md), [Technical Debt](/wiki/topics/technical-debt.md), [Architecture](/wiki/topics/architecture.md)

> Written by an LLM from machine transcripts. It can contain errors. Check the transcript before you quote it.

## Summary

The speaker argues that software developers often write unit tests mechanically without enough thought, leading to low return on investment and high duplication. To address this, the speaker proposes a systematic, five-step approach that guides developers through goal articulation, subject selection, test classification, dependency isolation, and chronological structuring. The audience learns practical heuristics to choose the right test subjects, avoid common anti-patterns like testing through side effects, and design more maintainable tests. Ultimately, the talk encourages a mindful approach to testing rather than relying on an automated routine.

## Key points

- [3:23](https://www.youtube.com/watch?v=kl0BOJ8xu3U&t=203s) The speaker notes that developers often run on autopilot when writing unit tests, focusing on code aesthetics for production while treating tests mechanically.
- [9:44](https://www.youtube.com/watch?v=kl0BOJ8xu3U&t=584s) The speaker introduces a five-step framework for unit testing, beginning with articulating the goal of the test out loud.
- [13:00](https://www.youtube.com/watch?v=kl0BOJ8xu3U&t=780s) The second step focuses on correctly identifying the test subject to avoid verifying behavior in the wrong place or poking inside hidden abstractions.
- [23:44](https://www.youtube.com/watch?v=kl0BOJ8xu3U&t=1424s) The third step involves classifying the test as either a state test or an interaction test, noting that state tests dominate.
- [33:14](https://www.youtube.com/watch?v=kl0BOJ8xu3U&t=1994s) The fourth step covers isolating dependencies, distinguishing between good and bad dependencies, and using stubs versus mocks appropriately.
- [39:51](https://www.youtube.com/watch?v=kl0BOJ8xu3U&t=2391s) The fifth step emphasizes structuring the test chronologically like a story using a clear setup, action, and verification flow.

## Takeaways

- State your test goal clearly before writing code to maintain focus on the system behavior.
- Classify your tests as either state or interaction checks, ensuring state tests verify outputs or direct public side effects.
- Isolate bad dependencies such as threads, while letting effective and easily verifiable dependencies remain.
- Structure tests chronologically as a readable story and do not be afraid of minor code duplication across tests.

## Questions this talk answers

- How do I choose the correct test subject when a method involves multiple components?
- When should I use a mock instead of a stub in my unit tests?
- How can I refactor tests that rely on private methods or internal state?

## Technologies

Ruby, C#, Java

## Tags

best practices, refactoring, software design, tdd, unit testing
