Skip to main content

Mock Data

Seed SObject records into the local mock store before test execution using --mock-data.


Usageโ€‹

squirex run -d force-app/main/default/classes --mock-data testdata.json

testdata.json Shapeโ€‹

{
"Account": [
{ "Name": "Acme Corp", "Industry": "Technology", "AnnualRevenue": 1000000 },
{ "Name": "Globex Inc", "Industry": "Finance", "AnnualRevenue": 500000 }
],
"Contact": [
{ "FirstName": "John", "LastName": "Doe", "Email": "john@acme.com", "AccountId": "@Account[0]" }
],
"Opportunity": [
{ "Name": "Q1 Deal", "StageName": "Prospecting", "CloseDate": "2026-06-30", "Amount": 50000 }
]
}

Records are inserted into the mock SOQL store in declaration order before any test method runs. SOQL queries in your Apex will find them.

@SObjectName[index] references

Use @Account[0] to reference the auto-generated Id of the first Account record. This mirrors how Apex developers use insertedRecord.Id in setup code.


What Gets Seededโ€‹

  • All records from the JSON are inserted with auto-generated Id fields
  • Relationships between objects are resolved via @ references
  • Standard Salesforce fields (CreatedDate, LastModifiedDate, OwnerId) are auto-populated with defaults

Example: Using Mock Data in Testsโ€‹

testdata.json:

{
"Account": [
{ "Name": "Mock Corp", "Industry": "Technology" }
]
}

Apex test:

@isTest
private class AccountServiceTest {
@isTest
static void testFindByIndustry() {
// Mock data pre-seeded โ€” no need for @testSetup
List<Account> results = [SELECT Name FROM Account WHERE Industry = 'Technology'];
System.assertEquals(1, results.size());
System.assertEquals('Mock Corp', results[0].Name);
}
}

Run:

squirex run --method AccountServiceTest.testFindByIndustry --mock-data testdata.json