Editing
AI assistants in coding
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Prompt for Generate Unit Tests === JetBrain 推出 [https://plugins.jetbrains.com/plugin/22282-ai-assistant AI Assistant 外掛]功能,目前付費客戶可以免費試用 7 天。它下的 prompt,供大家參考 ==== Prompt from JetBrain ==== <pre> Write "XXXClassTest' tests for the 'xxx' method in the "XXXClass' class. Guideline: '*' - Write a description of the class and the method being tested. - Test file should be complete and compilable, without need for further actions. - Ensure that each test focuses on a single use case to maintain clarity and readability. - PHP test file MUST starts with php opening tag ?php - Generated test class should be in namespace XXX''* File: XXXClass.php '''php ?php class XXXClass { ... ''' </pre> ==== Prompt with Complete Testing Strategy ==== <pre> Write complete unit tests for the "$METHOD_NAME" method in the "$CLASS_NAME" class. ## Test Target - Class: $CLASS_NAME - Method: $METHOD_NAME - Test Class Name: ${CLASS_NAME}Test - Namespace: $NAMESPACE - Source File: $FILE_NAME ## Source Code \```php $CODE \``` ## Writing Conventions **File Structure** - Test file must begin with `<?php` - Namespace should be `Tests\$NAMESPACE` - Place test file at `__tests__/${CLASS_NAME}Test.php` **Test Conventions** - Extend `PHPUnit\Framework\TestCase` - Each test method should cover only a single behavior - Method naming format: `test_[method_name]_[scenario_description]` - Use `setUp()` to initialize shared objects **Coverage** - Happy Path: expected results under normal input - Edge Cases: boundary values, null values, extreme inputs - Error States: thrown exceptions, error returns ## Output Requirements - Test file must be complete and executable without any modifications - Add a comment above each test method describing its purpose - Include the CLI command to run the test file </pre> Instruction of Complete Testing Strategy 1. '''Happy Path''' — Verifies the program behaves correctly under expected, valid inputs. <pre lang="php"> // e.g. formatDate should return the correct format when given a valid date $this->assertSame('2024/01/15', $this->formatter->format('2024-01-15')); </pre> 2. '''Edge Cases''' — Covers extreme or atypical but still valid inputs. <pre lang="php"> // e.g. empty string, zero value, maximum integer, boundary date $this->assertSame('', $this->formatter->format('')); </pre> 3. '''Error States''' — Validates how the program handles illegal inputs or system failures. <pre lang="php"> // e.g. should throw an exception or degrade gracefully when an invalid date is passed $this->expectException(\InvalidArgumentException::class); $this->formatter->format(null); </pre> ==== Simple version ==== <pre> Write PHPUnit test case including edge cases '''php function xxx(){ ... ''' </pre>
Summary:
Please note that all contributions to LemonWiki共筆 are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
LemonWiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
Tools
What links here
Related changes
Special pages
Page information