Published Sep 3, 2019

Episode 70: Gerard Meszaros on XUnit Test Patterns

Gerard Meszaros delves into XUnit Test Patterns, focusing on creating maintainable tests, managing test fixtures, and addressing common test smells. He underscores the importance of simplicity and automated testing in agile development to ensure software testability and continuous feedback.
Episode Highlights
Software Engineering Radio - the podcast for professional software developers logo

Popular Clips

Episode Highlights

  • Test Smells

    Gerard Meszaros introduces the concept of test smells, drawing parallels to code smells as defined by Martin Fowler and Kent Beck. He categorizes these smells into code, behavior, and project smells, each representing different symptoms encountered during testing. Meszaros elaborates on project smells, which are often visible to project managers when bugs appear in production, indicating issues like inadequate test-driven development or lack of proper training for developers 1 2.

    The test smells sort of fall into three categories. And by categories, I mean it's around how you discover the smell.

    ---

    These categories help identify the root causes of testing issues and guide the application of appropriate patterns to resolve them 3.

       

    Behavior Smells

    Behavior smells, according to Gerard Meszaros, are particularly insidious as they manifest unpredictably during test execution. These include erratic tests that pass or fail based on circumstances like time of day or system state, often due to unrepeatable tests or resource optimism 4 5. Meszaros explains that debugging these issues can be complex, requiring troubleshooting flowcharts to identify whether tests are interacting with each other or suffering from shared resource conflicts 6.

    Behavior smells really come and they just come and chase you down and get you, and they bite your leg and hang on until you do something about them.

    ---

    Addressing these smells often involves setting up fresh fixtures for each test to ensure consistency and reliability.

       

    Code Smells

    Code smells in test code can make it difficult to read and maintain, often due to obscure logic or poor structure. Gerard Meszaros emphasizes the importance of writing maintainable tests, as they are optional and can be discarded if they become too cumbersome 7 8. He suggests using test patterns to improve test code quality, ensuring tests are robust and easy to understand.

    The problem with that analogy is if I refactor my production code and the tests don't break, I was successful.

    ---

    Testing the tests themselves is crucial, often involving fault injection to verify their effectiveness 9.

Related Episodes