Testing - unit tests with unique values

Hi All,

I’ve put together some unit tests for my custom doc type. I’ve also put together corresponding test records in test_records.json.

All the test records are inserted correctly when running unit tests for the first time. However, I have a unique field type in my custom doctype, which raises an error when running my unit tests a second time.

What’s the best way to handle test data for doctypes with unique data fields? Is there an override function for this behaviour, or is there a way to remove test records after a successful run?

Thanks!

@dev_za don’t use test_records.json. Its an old way of writing tests that we want to discontinue (soon!)

Just create the records you need in your test.

Thanks!

Is there an example in the ERPNext codebase that I can use as a reference?