home / skills / venkateshvenki404224 / frappe-apps-manager / frappe-integration-test-generator

frappe-integration-test-generator skill

/frappe-apps-manager/skills/frappe-integration-test-generator

This skill generates comprehensive integration tests for multi-DocType Frappe workflows, enabling end-to-end scenario validation and state-transition

npx playbooks add skill venkateshvenki404224/frappe-apps-manager --skill frappe-integration-test-generator

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
3.2 KB
---
name: frappe-integration-test-generator
description: Generate integration tests for multi-DocType workflows in Frappe. Use when testing end-to-end workflows, state transitions, or complex business processes.
---

# Frappe Integration Test Generator

Generate comprehensive integration tests for multi-DocType workflows and end-to-end business processes in Frappe.

## When to Use This Skill

Claude should invoke this skill when:
- User wants to test complete workflows
- User needs end-to-end scenario testing
- User mentions integration tests or workflow testing
- User wants to test multi-DocType interactions
- User needs to verify business process integrity

## Capabilities

### 1. Workflow Integration Test

**Complete Sales Workflow Test:**
```python
from frappe.tests.utils import FrappeTestCase
import frappe

class TestSalesWorkflow(FrappeTestCase):
    def test_complete_sales_cycle(self):
        """Test end-to-end sales process"""
        # 1. Create Customer
        customer = self._create_test_customer()

        # 2. Create Sales Order
        so = self._create_sales_order(customer.name)
        so.submit()

        # 3. Create Sales Invoice from SO
        si = self._make_sales_invoice_from_order(so.name)
        si.insert()
        si.submit()

        # 4. Create Payment Entry
        pe = self._create_payment_entry(si)
        pe.insert()
        pe.submit()

        # Verify workflow completed
        si.reload()
        self.assertEqual(si.status, 'Paid')
        self.assertEqual(si.outstanding_amount, 0)

    def _create_test_customer(self):
        return frappe.get_doc({
            'doctype': 'Customer',
            'customer_name': '_Test Customer',
            'customer_group': 'Commercial'
        }).insert()

    def _create_sales_order(self, customer):
        return frappe.get_doc({
            'doctype': 'Sales Order',
            'customer': customer,
            'delivery_date': frappe.utils.add_days(frappe.utils.today(), 7),
            'items': [{
                'item_code': '_Test Item',
                'qty': 10,
                'rate': 100
            }]
        })
```

### 2. State Transition Test

**Test Document States:**
```python
class TestInvoiceStates(FrappeTestCase):
    def test_invoice_state_transitions(self):
        """Test all possible state transitions"""
        si = self._get_test_invoice()

        # Draft state
        si.insert()
        self.assertEqual(si.docstatus, 0)
        self.assertEqual(si.status, 'Draft')

        # Submit transition
        si.submit()
        self.assertEqual(si.docstatus, 1)
        self.assertEqual(si.status, 'Submitted')

        # Cannot edit submitted
        si.customer = 'Different Customer'
        with self.assertRaises(frappe.ValidationError):
            si.save()

        # Cancel transition
        si.cancel()
        self.assertEqual(si.docstatus, 2)
        self.assertEqual(si.status, 'Cancelled')
```

## References

**Integration Test Examples:**
- Sales Invoice Tests: https://github.com/frappe/erpnext/blob/develop/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
- Stock Entry Tests: https://github.com/frappe/erpnext/blob/develop/erpnext/stock/doctype/stock_entry/test_stock_entry.py

Overview

This skill generates integration tests for multi-DocType workflows in Frappe, focusing on end-to-end business processes and state transitions. It produces ready-to-run test scaffolding, sample helper methods, and assertions to verify data integrity and lifecycle changes across related documents. Use it to speed up coverage for complex workflows and reduce manual test authoring.

How this skill works

The skill inspects a described workflow or sample DocTypes and produces FrappeTestCase-based test classes that create, submit, transform, and cancel documents in sequence. It includes helper factory methods for creating test fixtures, asserts for expected states and amounts, and examples for verifying transitions and validation errors. Outputs are organized as Python test methods that can be adapted into your app's tests folder.

When to use it

  • Validating complete end-to-end business workflows that span multiple DocTypes.
  • Verifying state transitions (draft → submitted → cancelled) and lifecycle rules.
  • Testing multi-document interactions like Sales Order → Invoice → Payment Entry.
  • Automating regression checks for complex business logic after code changes.
  • Creating baseline integration tests when onboarding new features or modules.

Best practices

  • Isolate test data using helper methods that insert minimal required fields and clean up after run.
  • Use assertions for both state (docstatus/status) and numeric invariants (outstanding amount, totals).
  • Keep tests deterministic: set explicit dates, item codes, and currencies to avoid environment variability.
  • Test negative flows too: expect ValidationError for forbidden edits or invalid transitions.
  • Group related assertions in one end-to-end test and keep smaller focused tests for single transitions.

Example use cases

  • Generate a full sales cycle test: create Customer → Sales Order → Sales Invoice → Payment Entry and assert 'Paid' status.
  • Create state transition tests for invoices to exercise draft, submit, and cancel behavior and forbidden edits.
  • Produce tests that exercise multi-DocType business rules, e.g., stock reservation across Sales Order and Stock Entry.
  • Scaffold tests for custom workflows introduced by a new app to ensure regression safety.
  • Create parameterized tests for the same workflow under different customer groups, price lists, or taxes.

FAQ

Can these tests run in CI?

Yes — the generated FrappeTestCase tests are designed to run in standard Frappe CI environments with the site's test runner and appropriate fixtures.

Will the skill modify my production data?

No — tests use inserted test fixtures that should be isolated to the test database; run them only against test or CI environments.