doc/user/gitlab_duo/prompt_examples/generate_tests.md
Follow these guidelines when you need to create comprehensive test coverage for existing functions or classes.
Create thorough test coverage for existing code without manually writing boilerplate test cases and setup code.
Select code, generate tests, and refine coverage by using GitLab Duo Chat and Code Suggestions.
Select the function or class you want to test, then use GitLab Duo Chat to generate tests.
Generate tests for the selected [function_name/ClassName] by using [test_framework]:
1. Include test cases for normal operation
2. Add edge cases and error conditions
3. Test boundary values and invalid inputs
4. Follow [testing_conventions] for our project
5. Include setup and teardown if needed
Make the tests comprehensive but readable.
Expected outcome: Complete test file with multiple test cases covering different scenarios.
Review the generated tests and ask for specific improvements.
Review the generated tests and:
1. Add any missing edge cases for [specific_functionality]
2. Improve test names to be more descriptive
3. Add comments explaining complex test scenarios
4. Ensure tests follow [specific_style_guide]
Focus on making tests maintainable and clear.
Expected outcome: Polished test file with clear, comprehensive coverage.
Use Code Suggestions to add additional test cases. Type this text in your file.
// Test [specific_edge_case_scenario]
// Test [error_condition]
// Test [boundary_condition]
Expected outcome: Code Suggestions helps complete additional test cases.
Ensure that: