Anyone been able to run tests within a scratch org as a separate user created in the scratch org via the CLI?
We require the running user to have a particular setup in order for tests to run correctly. We're able to create the user via the CLI, but when we attempt a 'sfdx force:apex:test:run -u <username here>' we get 'Unable to invoke async test job: expired access/refresh token.'
If I attempt to authorize the newly created user with the devhub via 'sfdx force:auth:jwt:grant ...' we receive 'invalid_grant - user hasn't approved this consumer'.
All of this is being done as part of our continuous integration script - so would love to hear if anyone has an idea on how to work through this.
6 comments
+1 for using system.runAs inside of tests to ensure that you get consistent results no matter who runs the test. Users can be created for this purpose in the test itself (they don't even have to be inserted into the database)