ERPNext Unittest, How to setup?


I’ve tried to create simple unittest for custom app.

But when I tried to create Sales Order using make_sales_order, I got LinkValidationError

I know that creating _Test Company, _Test Item and _Test Warehouse - _TC will solve the problem.

My question is
Is there a function or database can be use for creating test data for default ERPNext doctype ?


ERROR: test_transaction_base (custom_app.test.test_money_in_words.TestMoneyInWords)
Traceback (most recent call last):
  File "/home/frappe/bench/apps/custom_app/custom_app/test/", line 10, in test_transaction_base
  File "/home/frappe/bench/apps/erpnext/erpnext/selling/doctype/sales_order/", line 901, in make_sales_order
  File "/home/frappe/bench/apps/frappe/frappe/model/", line 224, in insert
  File "/home/frappe/bench/apps/frappe/frappe/model/", line 766, in _validate_links
  File "/home/frappe/bench/apps/frappe/frappe/", line 377, in throw
    msgprint(msg, raise_exception=exc, title=title, indicator='red', is_minimizable=is_minimizable)
  File "/home/frappe/bench/apps/frappe/frappe/", line 356, in msgprint
  File "/home/frappe/bench/apps/frappe/frappe/", line 316, in _raise_exception
    raise raise_exception(msg)
frappe.exceptions.LinkValidationError: Could not find Company: _Test Company, Row #1: Item Code: _Test Item, Row #1: Delivery Warehouse: _Test Warehouse - _TC

Ran 1 test in 1.398s

FAILED (errors=1)


import frappe
import unittest

class TestMoneyInWords(unittest.TestCase):
    def test_transaction_base(self):
        from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
        so = make_sales_order(
        self.assertEqual(so.base_rounded_total, 'aaa')
        self.assertEqual(so.grand_total, 'aaa')
1 Like

I’ll :+1: this. Going to start testing some of my custom app. And I don’t see much docs apart from this. Which seems lacking for a huge framework like frappe, to only have one page explaining the basics of testing.

There is a bit more detail doc Frappe - Unit Testing.

But it doesn’t have anything on create test record.

Related issue

I meant creating test data for default ERPNext doctype.

So in Sales Order DocType it needs _Test Company, _Test Item and _Test Warehouse - _TC

Is there a function or database can be use for creating test data for default ERPNext doctype ?