generate_unit_test
WHEN: developer needs to write or scaffold unit tests for a custom D365 object. Triggers: 'generate tests', 'unit test', 'SysTest', 'write test for', 'scénarios de test', 'test this class'. Generate X++ SysTest unit test code for a CUSTOM D365 F&O object based on functional test scenarios. [!] Only meaningful on custom/extension code (D365_CUSTOM_MODEL_PATH). SysTest tests in D365 are highly context-specific -- a generic template rarely compiles without adaptation. REQUIRED: provide test scenarios in the 'testScenarios' parameter (supplied by the functional consultant). Each scenario becomes a concrete test method with arrange/act/assert. For tables: generates tests for find(), exist(), validateWrite(), initValue(). For classes: generates stubs for each public method listed in scenarios. Uses REAL field names and method signatures from the knowledge base.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| methodName | No | Optional: specific method to test. If not provided, generates tests for all testable methods. | |
| objectName | Yes | Object name to generate tests for, e.g. 'ALMERSftpConnectionTable', 'ALMMyClass' | |
| sampleValues | No | Optional: JSON object mapping field name to sample value used in each ARRANGE block, e.g. '{"AccountNum":"C0001","Amount":1500.50}'. Replaces the 'TODO: set up test data' placeholders with concrete assignments. | |
| testScenarios | No | Test scenarios provided by the functional consultant, e.g. 'Create a connection with valid SFTP host; Validate that empty host fails; Delete cleans up related records'. Separate scenarios with semicolons. |