The documentation says :
Tests that are started from the Salesforce user interface (including the Developer Console) run in parallel. Parallel test execution can speed up test run time. Sometimes, parallel test execution results in data contention issues, and you can turn off parallel execution in those cases. In particular, data contention issues and UNABLE_TO_LOCK_ROW errors might occur in the following cases.
So this is indeed due to parallel test execution which is the default behaviour, although you can disable it from the setup :
- From Setup, enter Apex Test Execution in the Quick Find box, select Apex Test Execution, then click Options
- In the Apex Test Execution Options dialog, select Disable Parallel Apex Testing and then click OK.
But you are getting this error when you run tests in CircleCI, so I suppose you do not have access to the scratch org to disable this setting from the UI. You then have 3 options :
Update the scratch org definition file to include the following apexSettings :
"settings": {
...,
"apexSettings": {
"enableDisableParallelApexTesting": true
},
...
}
This allows you to create scratch orgs that have the checkbox "Disable Parallel Apex Testing" checked by default, so test will not be executed in parallel.
- You can include in your package the following settings file, which needs to be deployed with the rest of your metadata to disable parallel test execution in your target org :
<?xml version="1.0" encoding="UTF-8"?>
<ApexSettings xmlns="http://soap.sforce.com/2006/04/metadata">
<enableDisableParallelApexTesting>true</enableDisableParallelApexTesting>
</ApexSettings>
- Find a way to store the login credentials of your created scratch org in your CirclCI build as artifacts. Check the answers here.