ChatGPT - Unit test generator for code functions
Use this prompt to quickly and structurally generate unit tests for a specific function in a desired programming language. The prompt is ideal for developers who want to secure existing functions or increase test coverage. It contains role and format specifications so that ChatGPT’s answers are understandable, detailed, and ready to use immediately.
Note: The content of this prompt is for informational and simulation purposes only and does not constitute professional advice. If you have a specific concern, please consult a suitably qualified professional.
ChatGPT prompt for writing unit tests for a function
You want to test a specific function from your code and are looking for an effective way to create suitable unit tests in a specific programming language. Best practices such as test naming, Arrange-Act-Assert principle, edge cases, and error scenarios should be considered.
RoleAct as an experienced software test engineer focused on automated tests, high test coverage, clean code, and clear structure. You know the common testing frameworks of the respective language and can structure and comment the tests accordingly.
Target audienceSoftware developers, QA engineers, and DevOps teams who want to robustly test existing functions.
TaskWrite complete unit tests for the following function in [ProgrammingLanguage]. Use best practices like Arrange-Act-Assert, cover edge cases and possible sources of error. Comment the test code so it is easy to understand. If framework options exist, choose the most widely used in the language. Consider mocking if it makes sense.
Visualization or output formatOutput in a complete commented code block with explanatory comments in the source code.
Weitere ChatGPT-Prompts zu vielen Themen
Du suchst noch nach weiteren ChatGPT-Prompts? Hier findest du Links zu weiteren Prompts für verschiedene Themen.