Skip to content

Commit

Permalink
added 85% minimum code coverage test
Browse files Browse the repository at this point in the history
  • Loading branch information
johnforeland committed Oct 20, 2020
1 parent 815ccbd commit c9213f7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
12 changes: 11 additions & 1 deletion .github/workflows/pull-request_validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,20 @@ jobs:
echo "::set-output name=classes::$( echo $classes | sed 's/\(.*\),/\1 /' )"
# Run Apex tests in scratch org
# TODO throw error on below 75% code coverage
- name: "Run Apex tests"
run: "sfdx force:apex:test:run -t ${{ steps.test-classes-in-repo.outputs.classes }} -c -r human -d ./tests/apex -w 20"

# Validate at least 85% code coverage
- name: Validate at least 85% code coverage
run:
codecoverage=$(cat tests/apex/test-result-7*.json | jq '.summary.testRunCoverage' | sed 's/\"//g; s/\%//g')
if [ $codecoverage -lt 85 ]
then
echo "Code coverage: $codecoverage%"
echo "Because it is less than 85%, the validation failed"
exit 125
fi

# Delete scratch orgs
- name: "Delete scratch org"
if: always()
Expand Down
11 changes: 11 additions & 0 deletions force-app/main/default/classes/testclass2.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public with sharing class testclass2 {
public static Boolean testFunc() {
System.debug('test');
return true;
}
}





5 changes: 5 additions & 0 deletions force-app/main/default/classes/testclass2.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>49.0</apiVersion>
<status>Active</status>
</ApexClass>
7 changes: 7 additions & 0 deletions force-app/main/default/classes/testclass2test.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@isTest
private without sharing class testclass2test {
@isTest
private static void testFunction() {
System.assert(testclass2.testFunc(), 'should be true');
}
}
5 changes: 5 additions & 0 deletions force-app/main/default/classes/testclass2test.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>49.0</apiVersion>
<status>Active</status>
</ApexClass>

0 comments on commit c9213f7

Please sign in to comment.