I have a test class like this:
Account acc = new Account(name='testAcc');
Insert acc;
Contact con = new Contact(LastName='TestContact', AccountId=acc.Id);
Insert con;
Id p = [SELECT Id FROM Profile WHERE Name = 'myCustomProfile' Limit 1].Id;
User runas = new User(Alias = 'testUser', Email='[email protected]',
EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='en_US', LocaleSidKey='en_US',
Profileid = p, Country='United States', IsActive=true, BU_Name__c = 'US', CompanyName = 'testCompany',
ContactId = con.Id, TimeZoneSidKey='America/Los_Angeles', Username='[email protected]');
Insert runas;
System.runAs(runas){
Test.startTest();
......
Test.stopTest();
}
However, I do not have 'myCustomProfile' in my scratch org if I run this:
sfdx force:org:create --setdefaultusername --definitionfile config/project-scratch-def.json --wait 10 --durationdays 7
With this project-scratch-def.json file:
{
"orgName": "myOrgName",
"edition": "Enterprise",
"hasSampleData": "true"
}
This caused the unit test of my unlocked package in the scratch org to fail. I guess there is a step that I might have missed. Or is there anything I can do to prevent this?