{"id":294,"date":"2025-08-13T22:43:40","date_gmt":"2025-08-13T22:43:40","guid":{"rendered":"https:\/\/makeaiprompt.com\/blog\/testing-and-debugging-ai-prompt\/"},"modified":"2025-08-16T19:57:27","modified_gmt":"2025-08-16T19:57:27","slug":"testing-and-debugging-ai-prompt","status":"publish","type":"post","link":"https:\/\/makeaiprompt.com\/blog\/testing-and-debugging-ai-prompt\/","title":{"rendered":"Testing and Debugging AI Prompt"},"content":{"rendered":"<div style=\"margin-top: 0px; margin-bottom: 0px;\" class=\"sharethis-inline-share-buttons\" ><\/div><div style=\"padding: 20px; border-radius: 8px; margin-bottom: 20px;\">\n<h3 style=\"margin-top: 0;\">About Prompt<\/h3>\n<ul style=\"list-style: none; padding: 0;\">\n<li style=\"margin: 8px 0; padding: 8px; border-radius: 4px; box-shadow: 0 1px 3px rgba(255, 255, 255, 1);\"><strong>Niche<\/strong> &#8211; Code Generation<\/li>\n<li style=\"margin: 8px 0; padding: 8px; border-radius: 4px; box-shadow: 0 1px 3px rgba(255, 255, 255, 1);\"><strong>Language<\/strong> &#8211; English<\/li>\n<li style=\"margin: 8px 0; padding: 8px; border-radius: 4px; box-shadow: 0 1px 3px rgba(255, 255, 255, 1);\"><strong>Category<\/strong> &#8211; Software Development<\/li>\n<li style=\"margin: 8px 0; padding: 8px; border-radius: 4px; box-shadow: 0 1px 3px rgba(255, 255, 255, 1);\"><strong>Prompt Title<\/strong> &#8211; Testing and Debugging AI Prompt<\/li>\n<\/ul>\n<\/div>\n<h3 style=\"margin-top: 0;\">Prompt:<\/h3>\n<div id=\"promptContent\">## AI Prompt: Generate Python Code with Unit Tests for [Specific Task]This prompt is designed to generate Python code along with comprehensive unit tests for the specified task. Please adhere to the following instructions and provide clear, well-documented code.<\/p>\n<p>**Task Description:**<br \/>\n[Provide a clear and concise description of the task. Be extremely specific about the desired functionality, including input formats, expected output formats, edge cases, and any specific algorithms or libraries to be used. For example, &#8220;Generate a function that takes a list of integers as input and returns a new list containing only the even numbers. Handle empty input lists and lists containing non-integer values.&#8221; or &#8220;Implement a class that represents a binary search tree. Include methods for insertion, deletion, search, and finding the minimum\/maximum values. The class should handle duplicate values and raise appropriate exceptions for invalid operations.&#8221;]<\/p>\n<p>**Code Requirements:**<\/p>\n<p>* **Language:** Python 3.9+<br \/>\n* **Style:** PEP 8 compliant. Use descriptive variable names and maintain consistent indentation.<br \/>\n* **Error Handling:** Implement robust error handling for invalid inputs, edge cases, and potential exceptions. Raise custom exceptions where appropriate with informative error messages.<br \/>\n* **Documentation:** Include docstrings for all functions and classes explaining their purpose, arguments, return values, and any exceptions raised. Use clear and concise language.<br \/>\n* **Efficiency:** Strive for efficient code with optimized algorithms and data structures. Avoid unnecessary computations or memory usage. If performance is critical, mention it explicitly in the task description.<\/p>\n<p>**Unit Tests Requirements:**<\/p>\n<p>* **Framework:** pytest<br \/>\n* **Coverage:** Aim for 100% branch coverage. Test all possible code paths, including edge cases, boundary conditions, and error handling logic.<br \/>\n* **Assertions:** Use clear and concise assertions to verify the expected behavior of the code.<br \/>\n* **Test Data:** Include a diverse set of test cases that cover all possible scenarios. Use parameterized tests where appropriate.<br \/>\n* **Test Organization:** Organize tests logically into test functions with descriptive names. Group related tests together.<\/p>\n<p>**Output Format:**<\/p>\n<p>The generated output should be formatted as a single Markdown code block containing:<\/p>\n<p>1. **Code Section:** The complete Python code implementation, including all necessary imports, functions, and classes.<br \/>\n2. **Test Section:** The complete pytest test suite.<\/p>\n<p>**Example (for a simple task):**<\/p>\n<p>&#8220;`markdown<br \/>\n&#8220;`python<br \/>\ndef even_numbers(numbers):<br \/>\n&#8220;&#8221;&#8221;<br \/>\nReturns a list containing only the even numbers from the input list.<\/p>\n<p>Args:<br \/>\nnumbers: A list of integers.<\/p>\n<p>Returns:<br \/>\nA list of even integers.<\/p>\n<p>Raises:<br \/>\nTypeError: If the input is not a list or contains non-integer values.<br \/>\n&#8220;&#8221;&#8221;<br \/>\nif not isinstance(numbers, list):<br \/>\nraise TypeError(&#8220;Input must be a list.&#8221;)<\/p>\n<p>even_nums = []<br \/>\nfor num in numbers:<br \/>\nif not isinstance(num, int):<br \/>\nraise TypeError(&#8220;List elements must be integers.&#8221;)<br \/>\nif num % 2 == 0:<br \/>\neven_nums.append(num)<br \/>\nreturn even_nums<\/p>\n<p>&#8220;`<\/p>\n<p>&#8220;`python<br \/>\nimport pytest<br \/>\nfrom your_module import even_numbers # Replace your_module<\/p>\n<p>def test_even_numbers_empty_list():<br \/>\nassert even_numbers([]) == []<\/p>\n<p>def test_even_numbers_all_even():<br \/>\nassert even_numbers([2, 4, 6]) == [2, 4, 6]<\/p>\n<p>def test_even_numbers_mixed():<br \/>\nassert even_numbers([1, 2, 3, 4, 5, 6]) == [2, 4, 6]<\/p>\n<p>def test_even_numbers_invalid_input():<br \/>\nwith pytest.raises(TypeError):<br \/>\neven_numbers(&#8220;not a list&#8221;)<\/p>\n<p>def test_even_numbers_non_integer_element():<br \/>\nwith pytest.raises(TypeError):<br \/>\neven_numbers([1, 2, &#8220;a&#8221;])<br \/>\n&#8220;`<br \/>\n&#8220;`<\/p>\n<p>**Note:** Replace &#8220;[Specific Task]&#8221; with a detailed description of the task you want the AI to perform. The more detail you provide, the better the generated code will be. This includes specific examples of inputs and expected outputs. If you have performance requirements, limitations on library usage, or specific coding patterns to follow, clearly articulate them within the Task Description.<\/p>\n<\/div>\n<div style=\"margin-top: 40px; text-align: center;\"><button id=\"copyPostContent\" style=\"background: #28a745; color: white; padding: 12px 24px; margin: 10px; border: none; border-radius: 5px; cursor: pointer;\">\ud83d\udccb Copy Prompt<\/button><\/div>\n<div style=\"margin-top: 40px; text-align: center;\"><a style=\"background: #0073aa; color: white; padding: 12px 24px; margin: 10px; text-decoration: none; border-radius: 5px; display: inline-block;\" href=\"https:\/\/makeaiprompt.com\">Create Your Own Prompts<\/a><br \/>\n<a style=\"background: #ff6600; color: white; padding: 12px 24px; margin: 10px; text-decoration: none; border-radius: 5px; display: inline-block;\" href=\"https:\/\/makeaiprompt.com\/top-ai-tools\">Top AI Tools<\/a><br \/>\n<a style=\"background: #ff6600; color: white; padding: 12px 24px; margin: 10px; text-decoration: none; border-radius: 5px; display: inline-block;\" href=\"https:\/\/chatgpt.com\/\" target=\"_blank\" rel=\"noopener\">Try on ChatGPT<\/a><br \/>\n<a style=\"background: #ff6600; color: white; padding: 12px 24px; margin: 10px; text-decoration: none; border-radius: 5px; display: inline-block;\" href=\"https:\/\/gemini.google.com\/app\" target=\"_blank\" rel=\"noopener\">Try on Gemini<\/a><br \/>\n<a style=\"background: #ff6600; color: white; padding: 12px 24px; margin: 10px; text-decoration: none; border-radius: 5px; display: inline-block;\" href=\"https:\/\/grok.com\" target=\"_blank\" rel=\"noopener\">Try on Grok<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>About Prompt Niche &#8211; Code Generation Language &#8211; English Category &#8211; Software Development Prompt Title &#8211; Testing and Debugging AI Prompt Prompt: ## AI Prompt: Generate Python Code with Unit Tests for [Specific Task]This prompt is designed to generate Python code along with comprehensive unit tests for the specified task. Please adhere to the following &#8230; <a title=\"Testing and Debugging AI Prompt\" class=\"read-more\" href=\"https:\/\/makeaiprompt.com\/blog\/testing-and-debugging-ai-prompt\/\" aria-label=\"Read more about Testing and Debugging AI Prompt\">Read more<\/a><\/p>\n","protected":false},"author":3,"featured_media":293,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1,3,7,5,6,4,8],"tags":[],"class_list":["post-294","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-prompts","category-chatgpt-prompts","category-copilot-prompts","category-deepseek-prompts","category-gemini-prompts","category-grok-prompts","category-midjourney-prompts"],"jetpack_featured_media_url":"https:\/\/makeaiprompt.com\/blog\/wp-content\/uploads\/2025\/08\/Testing-and-Debugging-AI-Prompt.jpg","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"rttpg_featured_image_url":{"full":["https:\/\/makeaiprompt.com\/blog\/wp-content\/uploads\/2025\/08\/Testing-and-Debugging-AI-Prompt.jpg",1200,630,false],"landscape":["https:\/\/makeaiprompt.com\/blog\/wp-content\/uploads\/2025\/08\/Testing-and-Debugging-AI-Prompt.jpg",1200,630,false],"portraits":["https:\/\/makeaiprompt.com\/blog\/wp-content\/uploads\/2025\/08\/Testing-and-Debugging-AI-Prompt.jpg",1200,630,false],"thumbnail":["https:\/\/makeaiprompt.com\/blog\/wp-content\/uploads\/2025\/08\/Testing-and-Debugging-AI-Prompt-150x150.jpg",150,150,true],"medium":["https:\/\/makeaiprompt.com\/blog\/wp-content\/uploads\/2025\/08\/Testing-and-Debugging-AI-Prompt-300x158.jpg",300,158,true],"large":["https:\/\/makeaiprompt.com\/blog\/wp-content\/uploads\/2025\/08\/Testing-and-Debugging-AI-Prompt-1024x538.jpg",1024,538,true],"1536x1536":["https:\/\/makeaiprompt.com\/blog\/wp-content\/uploads\/2025\/08\/Testing-and-Debugging-AI-Prompt.jpg",1200,630,false],"2048x2048":["https:\/\/makeaiprompt.com\/blog\/wp-content\/uploads\/2025\/08\/Testing-and-Debugging-AI-Prompt.jpg",1200,630,false]},"rttpg_author":{"display_name":"AI Prompts","author_link":"https:\/\/makeaiprompt.com\/blog\/author\/ai-prompts\/"},"rttpg_comment":0,"rttpg_category":"<a href=\"https:\/\/makeaiprompt.com\/blog\/category\/prompts\/\" rel=\"category tag\">Prompts<\/a> <a href=\"https:\/\/makeaiprompt.com\/blog\/category\/prompts\/chatgpt-prompts\/\" rel=\"category tag\">ChatGPT Prompts<\/a> <a href=\"https:\/\/makeaiprompt.com\/blog\/category\/prompts\/copilot-prompts\/\" rel=\"category tag\">Copilot Prompts<\/a> <a href=\"https:\/\/makeaiprompt.com\/blog\/category\/prompts\/deepseek-prompts\/\" rel=\"category tag\">Deepseek Prompts<\/a> <a href=\"https:\/\/makeaiprompt.com\/blog\/category\/prompts\/gemini-prompts\/\" rel=\"category tag\">Gemini Prompts<\/a> <a href=\"https:\/\/makeaiprompt.com\/blog\/category\/prompts\/grok-prompts\/\" rel=\"category tag\">Grok Prompts<\/a> <a href=\"https:\/\/makeaiprompt.com\/blog\/category\/prompts\/midjourney-prompts\/\" rel=\"category tag\">Midjourney Prompts<\/a>","rttpg_excerpt":"About Prompt Niche &#8211; Code Generation Language &#8211; English Category &#8211; Software Development Prompt Title &#8211; Testing and Debugging AI Prompt Prompt: ## AI Prompt: Generate Python Code with Unit Tests for [Specific Task]This prompt is designed to generate Python code along with comprehensive unit tests for the specified task. Please adhere to the following&hellip;","_links":{"self":[{"href":"https:\/\/makeaiprompt.com\/blog\/wp-json\/wp\/v2\/posts\/294","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/makeaiprompt.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/makeaiprompt.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/makeaiprompt.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/makeaiprompt.com\/blog\/wp-json\/wp\/v2\/comments?post=294"}],"version-history":[{"count":2,"href":"https:\/\/makeaiprompt.com\/blog\/wp-json\/wp\/v2\/posts\/294\/revisions"}],"predecessor-version":[{"id":463,"href":"https:\/\/makeaiprompt.com\/blog\/wp-json\/wp\/v2\/posts\/294\/revisions\/463"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/makeaiprompt.com\/blog\/wp-json\/wp\/v2\/media\/293"}],"wp:attachment":[{"href":"https:\/\/makeaiprompt.com\/blog\/wp-json\/wp\/v2\/media?parent=294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/makeaiprompt.com\/blog\/wp-json\/wp\/v2\/categories?post=294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/makeaiprompt.com\/blog\/wp-json\/wp\/v2\/tags?post=294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}