/frappe-apps-manager:frappe-testfrom frappe-apps-manager
Runs unit and integration tests for Frappe apps with coverage reports. Supports testing specific DocTypes, apps, or all apps.
Ships in frappe-apps-manager. Installing the plugin adds it to Claude Code.
Execute comprehensive tests for Frappe applications including unit tests, integration tests, and generate coverage reports.
pip install coverage pytest
Ask user what they want to test:
A. Specific DocType
test_[doctype_name].pyB. Specific App
C. All Apps
D. Specific Test File/Function
Offer test configuration options:
Basic Options:
--verbose: Show detailed test output--failfast: Stop on first failure--profile: Profile test execution timeCoverage Options:
--coverage: Generate coverage report--html-coverage: Generate HTML coverage reportTest Filtering:
Execute appropriate test command based on scope:
Test Specific DocType:
bench --site [site-name] run-tests \
--app [app-name] \
--doctype "[DocType Name]" \
[--verbose] \
[--coverage]
Test Specific App:
bench --site [site-name] run-tests \
--app [app-name] \
[--module [module-name]] \
[--verbose] \
[--coverage]
Test All Apps:
bench --site [site-name] run-tests \
[--verbose] \
[--coverage]
Test Specific File:
bench --site [site-name] run-tests \
--test [path/to/test_file.py] \
[--verbose]
Test with Coverage:
bench --site [site-name] run-tests \
--app [app-name] \
--coverage \
--coverage-report-html
Display progress information:
After test completion, show:
Test Summary:
Failed Test Details: For each failed test:
Coverage Report (if enabled):
Name Stmts Miss Cover
-----------------------------------------------------------
my_app/my_module/doctype/my_doctype.py 150 20 87%
my_app/api.py 80 10 88%
-----------------------------------------------------------
TOTAL 230 30 87%
If HTML coverage requested, generate and show:
# Coverage report location
frappe-bench/sites/coverage_html/index.html
# Open in browser (offer to open)
xdg-open sites/coverage_html/index.html
If tests fail, offer debugging help:
Common Issues:
Debugging Commands:
# Run single test with pdb
bench --site [site-name] run-tests --test [test-file] --pdb
# Run tests with logging
bench --site [site-name] run-tests --app [app-name] --verbose
# Check test data
bench --site [site-name] console
Suggest setting up continuous testing:
Watch Mode:
# Re-run tests on file changes (if using pytest-watch)
ptw -- bench --site [site-name] run-tests --app [app-name]
Pre-commit Hooks:
# Add to .git/hooks/pre-commit
#!/bin/bash
bench --site test_site run-tests --app my_app --failfast
Offer to export test results:
JUnit XML (for CI/CD):
bench --site [site-name] run-tests \
--app [app-name] \
--junit-xml test-results.xml
JSON Report:
bench --site [site-name] run-tests \
--app [app-name] \
--json-report test-results.json
Test Structure:
import frappe
import unittest
class TestMyDocType(unittest.TestCase):
def setUp(self):
"""Set up test fixtures"""
frappe.set_user("Administrator")
def tearDown(self):
"""Clean up after test"""
frappe.db.rollback()
def test_creation(self):
"""Test DocType creation"""
doc = frappe.get_doc({
"doctype": "My DocType",
"field1": "value1"
})
doc.insert()
self.assertEqual(doc.field1, "value1")
def test_validation(self):
"""Test validation logic"""
doc = frappe.get_doc({
"doctype": "My DocType",
"field1": "" # Required field
})
self.assertRaises(frappe.ValidationError, doc.insert)
Test Categories:
Using Fixtures:
def setUp(self):
# Load test fixtures
frappe.get_test_records("Item")
frappe.get_test_records("Customer")
Creating Test Data:
def create_test_customer(self):
customer = frappe.get_doc({
"doctype": "Customer",
"customer_name": "Test Customer",
"customer_type": "Company"
})
customer.insert(ignore_if_duplicate=True)
return customer
"No module named 'coverage'"
pip install coverage"Site does not exist"
bench new-site test_site"Permission Error"
"Database Errors"
"Import Error"
Use Transaction Rollback:
def tearDown(self):
frappe.db.rollback() # Faster than deleting records
Parallel Testing (Experimental):
bench --site [site-name] run-tests --app [app-name] --parallel
Skip Slow Tests in Development:
@unittest.skip("Slow integration test")
def test_complex_workflow(self):
pass
Use Test Markers:
@pytest.mark.slow
def test_heavy_operation(self):
pass
# Run only fast tests
pytest -m "not slow"
Learn from Frappe Framework Tests:
test_db.py - Database testing patternstest_document.py - DocType testingtest_permissions.py - Permission testingtest_api.py - API endpoint testingERPNext Test Examples:
sales_invoice/test_sales_invoice.py - Transaction testingpayment_entry/test_payment_entry.py - Complex workflowsstock_entry/test_stock_entry.py - Inventory testingitem/test_item.py - Master data testingReal Test Patterns from Core Apps:
# See: erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
def test_sales_invoice_with_discount(self):
si = frappe.copy_doc(test_records[0])
si.discount_amount = 104.95
si.append("items", {
"item_code": "_Test Item",
"qty": 10,
"rate": 100
})
si.insert()
si.submit()
self.assertEqual(si.total, 1000)
self.assertEqual(si.grand_total, 895.05)
# See: frappe/tests/test_permissions.py
def test_user_permissions(self):
frappe.set_user("[email protected]")
# Test read permission
doc = frappe.get_doc("DocType Name", "DOC-001")
# Test write permission
doc.field = "new_value"
doc.save()
# See: frappe/tests/test_api.py
def test_api_call(self):
from frappe.handler import execute_cmd
frappe.set_user("Administrator")
response = execute_cmd("my_app.api.method_name")
self.assertEqual(response["status"], "success")
name: Run Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Bench
run: |
# Setup Frappe bench
bench init frappe-bench
cd frappe-bench
bench new-site test_site
bench --site test_site install-app my_app
- name: Run Tests
run: |
cd frappe-bench
bench --site test_site run-tests \
--app my_app \
--coverage \
--junit-xml test-results.xml
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
if: always()
with:
files: frappe-bench/test-results.xml
def test_api_endpoint(self):
response = frappe.get_doc({
"doctype": "Integration Request",
"integration_type": "Remote",
"url": "/api/method/my_app.api.get_data"
})
self.assertEqual(response.status_code, 200)
def test_query_performance(self):
import time
start = time.time()
# Run query
frappe.db.get_all("Item", limit=1000)
duration = time.time() - start
self.assertLess(duration, 1.0) # Should complete in < 1 second
from unittest.mock import patch
def test_with_mock(self):
with patch('frappe.sendmail') as mock_email:
# Test email sending without actually sending
doc.send_notification()
mock_email.assert_called_once()
Recommended Structure:
my_app/
├── my_module/
│ └── doctype/
│ └── my_doctype/
│ ├── my_doctype.py
│ ├── my_doctype.json
│ ├── my_doctype.js
│ └── test_my_doctype.py ← Unit tests
├── tests/
│ ├── __init__.py
│ ├── test_integration.py ← Integration tests
│ └── test_api.py ← API tests
└── fixtures/
└── test_data.json ← Test fixtures
Files this command reads when invoked
What the command file sets; muted values are Claude Code's defaults
7-day visitors to each command page
npx claudepluginhub vyogotech/frappe-apps-manager --plugin frappe-apps-manager15 commands in this plugin
/frappe-backupFrappe Backup CommandBackup Frappe site data and files/frappe-bench-startFrappe Bench Start CommandStart Frappe bench with proper configuration/frappe-cacheFrappe Cache CommandManage Redis cache - clear, monitor, and optimize Frappe cache performance/frappe-configFrappe Config CommandConfigure Frappe site settings - manage site_config.json and environment variables/frappe-consoleFrappe Console CommandLaunch interactive Frappe Python console for debugging and data queries/frappe-db-resetFrappe DB Reset CommandReset Frappe database - reinstall with fresh data and fixtures for development2 plugins ship this exact command · first indexed Dec 31, 2025
Other plugins' commands for the same job