I'm not SF expert. I'm helping another team to improve and apply some code standards.
How to check the test coverage before git push? I'm trying to deploy and execute staged Apex Classes tests before the git push using SF CLI.
What I'm trying to achieve is to check only the staged classes' test coverage and if their tests are passed before the code is pushed into the repository. So I'm using lint-staged to find all staged Class Names and their Tests and SF CLI to deploy and run the tests. Based on the results I check if tests are passing and if test coverage is above the threshold.
What I don't understand:
- Is this a valid/good idea in general?
- What is the right way to do it? ( is --dray-run ok?)
Should I think for --dry-run
like it is compiling only the listed classes on the side and then running tests on it?
sf project deploy start --metadata ApexClass:PubSubSomething ApexClass:QueueableSomething ApexClass:AnotherExample --junit --tests PubSubSomethingTest QueueableSomethingTest AnotherExampleTest --dry-run --ignore-conflicts --json --results-dir ./.tests/apex --coverage-formatters=json --target-org ExampleOrg