Published Sep 3, 2019

SE-Radio Episode 256: Jay Fields on Working Effectively with Unit Tests

Jay Fields shares expert insights on navigating unit testing challenges, emphasizing the importance of maintaining valuable tests, evaluating testing ROI, and crafting effective strategies for enhancing software quality and productivity.
Episode Highlights
Software Engineering Radio - the podcast for professional software developers logo

Popular Clips

Episode Highlights

  • Types of Testing

    explores the nuances of unit testing by distinguishing between solitary and sociable unit tests. Solitary unit tests focus on testing individual components in isolation, avoiding dependencies like databases or file systems, which ensures speed and reliability. Sociable unit tests, on the other hand, verify the integration of components, albeit at the cost of speed and potential brittleness 1. emphasizes the importance of balancing these two approaches to achieve comprehensive test coverage without sacrificing efficiency 2. He states,

    I like to do is write as many solitary unit tests as I possibly can and then write one or two sociable unit tests.

    ---

    This strategy allows developers to test corner cases with solitary tests while ensuring overall system integration with a few sociable tests 3.

       

    Testing Pyramid

    The testing pyramid is a crucial concept in software development, providing a structured approach to test layering. describes the pyramid's base as consisting of numerous solitary unit tests, which ensure individual components function correctly 4. The middle layer comprises sociable unit tests that confirm component interactions, while the top layer includes high-level tests that validate the entire system's behavior.

    At the bottom, you have a very wide base of the pyramid, and that's where all of your solitary unit tests go.

    ---

    This hierarchical approach helps maintain a balance between thorough testing and efficient execution, with recommending a ratio that favors solitary tests to minimize maintenance overhead 5.

       

    Behavior vs State

    In unit testing, understanding the difference between behavior and state verification is essential for ensuring software quality. State verification involves checking the system's state after executing code, while behavior verification focuses on the interactions and outputs during execution 6. explains that behavior verification often involves mocking dependencies to confirm expected interactions, whereas state verification relies on asserting expected outcomes.

    You're actually comparing the behavior. You're not necessarily comparing the results of the behavior.

    ---

    Both methods have their place in a robust testing strategy, and suggests that developers should be familiar with both to choose the most effective approach for their specific needs 7.

Related Episodes