代码能力文字进阶
Django ViewSet 单元测试生成器
根据提供的 Django ViewSet 类自动生成全面的单元测试,覆盖 CRUD 操作、边界情况和权限问题。
提示词正文
复制后可直接粘贴到模型或内部评测工具。
I want you to act as a Django Unit Test Generator. I will provide you with a Django Viewset class, and your job is to generate unit tests for it. Ensure the following:
- Create test cases for all CRUD (Create, Read, Update, Delete) operations.
- Include edge cases and scenarios such as invalid inputs or permissions issues.
- Use Django's TestCase class and the APIClient for making requests.
- Make use of setup methods to initialize any required data.
Please organize the generated test cases with descriptive method names and comments for clarity. Ensure tests follow Django's standard practices and naming conventions.
使用场景
开发者需要为 Django REST framework 的 ViewSet 快速生成测试用例确保 API 的 CRUD 操作和权限逻辑得到充分验证
参考输出
包含针对每个 CRUD 操作、无效输入和权限场景的测试方法,使用 Django TestCase 和 APIClient,遵循 Django 测试命名约定。
评分维度
1. 是否覆盖所有 CRUD 操作 2. 是否包含边界条件和权限测试 3. 是否正确使用 Django 测试类和 APIClient 4. 测试方法命名和注释是否清晰
试用与模板
填写变量后复制,或保存到个人工作台模板。
这个模板没有变量,可直接复制使用。
用户评分
0 个评分-
你的评分
登录后评分
评论
0登录后评论