Skip to content
Back to skills

Frappe Testing

ASecurity

Frappe/ERPNext tests and CI. Use when writing unit or integration tests for a DocType or app, running bench run-tests, or setting up CI (GitHub Actions) for a Frappe app.

  • 10 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 24, 2026
ai-agentspythonbashtestinggitapi

Works with

  • api

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned November 27, 2026

npx -y skills add irfanzahoor/frappe_core_skills --skill frappe-testing --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Frappe Testing?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Frappe Testing
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/irfanzahoor-frappe-testing/badge)](https://www.skillsdirectory.com/skills/irfanzahoor-frappe-testing)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: frappe-testing
description: Frappe/ERPNext tests and CI. Use when writing unit or integration tests for a DocType or app, running bench run-tests, or setting up CI (GitHub Actions) for a Frappe app.
---

# Frappe Testing

## Where
`<app>/<module>/doctype/<name>/test_<name>.py`. The file must start with `test_`, or the runner ignores it.

## Base class

| Version | Needs DB? | Class |
|---|---|---|
| v15+ | no (pure logic) | `from frappe.tests.classes import UnitTestCase` |
| v15+ | yes | `from frappe.tests.classes import IntegrationTestCase` |
| v14 | any | `from frappe.tests.utils import FrappeTestCase` |

Each test runs in a transaction that rolls back afterwards. Never call `frappe.db.commit()` in tests.
If you override `setUpClass`, call `super().setUpClass()`.

```python
import frappe
from frappe.tests.classes import IntegrationTestCase

class TestLoanApplication(IntegrationTestCase):
    def test_amount_must_be_positive(self):
        doc = frappe.get_doc({"doctype": "Loan Application", "amount": -1})
        self.assertRaises(frappe.ValidationError, doc.insert)
```

Rules:
- Test behaviour: validations throw, totals compute, submit/cancel work, permissions deny.
- Create the test data inside the test, or with `test_records.json` next to the DocType.
  Don't depend on production data.
- Check permissions with `frappe.set_user("test@example.com")`, and always restore the user in
  `tearDown` or a `finally` block (`frappe.set_user("Administrator")`) so a failing test can't leak it.
- Mock external HTTP calls (`unittest.mock.patch`). Never call real APIs in tests.

## Run

```bash
bench --site test_site set-config allow_tests true
bench --site test_site run-tests --app myapp
bench --site test_site run-tests --doctype "Loan Application"
bench --site test_site run-tests --doctype "Loan Application" --test test_amount_must_be_positive
bench --site test_site run-tests --app myapp --failfast --junit-xml-output report.xml
```

Use a separate test site, never production.

## CI (GitHub Actions)
Use the workflow that `bench new-app` generates (`.github/workflows/ci.yml`). It runs MariaDB and Redis
services, `bench init --frappe-branch version-15`, `get-app` the repo, `new-site`, `install-app`, then
`run-tests --app myapp`. Pin the same Frappe branch the app targets.

Files in this skill

  • SKILL.md2.2 KB
  • references/test-patterns.md2.8 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.