Generate a test suite with GitHub Copilot and PDD

The video demonstrates how to use prompt-driven development alongside GitHub Copilot to efficiently generate a comprehensive and well-structured test suite for a Golang weather app, covering unit, integration, and end-to-end tests with high code coverage. It highlights the process of guiding Copilot with clear prompts to create mock-based tests, iteratively refining them, and emphasizes the importance of developer review to ensure test quality.

In this video, the presenter demonstrates how to use prompt-driven development (PDD) combined with GitHub Copilot to efficiently generate a comprehensive test suite for a Golang web application. The application in question is a weather app that fetches weather data such as temperature and humidity from the OpenWeatherMap API and displays it either via a UI or CLI. Before diving into test creation, the presenter explains the app’s structure, highlighting key files like main.go and the configuration setup, to provide context for the testing process.

The core concept of prompt-driven development is introduced as a way to guide an AI assistant, like GitHub Copilot, to write purposeful code based on natural language descriptions. Instead of manually writing tests, the developer writes clear prompts that instruct Copilot on what to generate. The presenter starts by asking Copilot to create blank test files for all relevant parts of the application, referencing an agent.md file that outlines the desired testing framework, including the testing pyramid and a standard test format involving arrange, act, and assert steps.

Next, the focus shifts to writing actual tests, particularly for the weather API component. Using a vague but strategic prompt, the presenter instructs Copilot to create unit tests that incorporate a mocking strategy detailed in the agent.md file. This approach avoids spinning up real servers during testing by using mock servers and mock data. Copilot successfully generates well-structured tests using table-driven testing, covering various scenarios including API success and error responses, and the tests pass when run, demonstrating the effectiveness of this method.

Building on this success, the presenter then prompts Copilot to write a full test suite for the remaining files, including code coverage reporting. Copilot analyzes the codebase and generates tests for configuration, server, and CLI components, again using table-driven tests and removing skipped tests. Some initial test failures occur due to issues with an M file containing API keys, but Copilot iteratively fixes these problems by renaming or adjusting the file handling. Eventually, the test suite achieves around 90% coverage and all tests pass successfully.

The video concludes by highlighting the power of combining prompt-driven development with GitHub Copilot to automate and accelerate the creation of a robust test suite. The presenter emphasizes that while Copilot handles much of the heavy lifting, developers still need to review and refine the generated tests. The approach covers unit, integration, and end-to-end tests, providing a solid foundation for maintaining code quality. Viewers are encouraged to like, subscribe, and explore more videos for further learning.