Table of Contents
- Overview
- Prerequisites
- Generate a Python Class from Comments
- Extend with Domain-Specific Methods
- Comment-Driven Function Generation
- Auto-Generate Unit Tests
- Resources & References
Overview
Comment-driven development (CDD) lets you write plain-English comments that describe the code you need. GitHub Copilot reads these comments and generates the corresponding implementation, including:- Classes with type hints and validation
- Data-processing methods
- Standalone functions
pytestunit tests
Prerequisites
Before you begin, ensure the following are installed:Generate a Python Class from Comments
Openmain.py and write a high-level description of the class you want:
GitHub Copilot will trigger on typing patterns like
def or class. Press Tab (or your configured shortcut) to accept the suggestion.Instantiate and Verify
Extend with Domain-Specific Methods
You can drive Copilot to add data-processing methods by writing comments in the class. For example, to analyze stock data:Employee class. Running main.py again confirms existing behavior is preserved:
Comment-Driven Function Generation
Standalone functions are just as easy. Inmain.py, add:
Auto-Generate Unit Tests
Createtest_main.py and write test-descriptive comments:
Always review generated code for edge cases and security considerations—AI suggestions may not cover every scenario.