ApexUnit is a powerful continuous integration tool for the Force.com platform
ApexUnit is a continuous integration tool for the Force.com platform that executes Apex tests and fetches code coverage results.
ApexUnit comprises of two major components:
Please refer https://github.com/forcedotcom/ApexUnit/wiki to learn more about the key features of ApexUnit and its usage
curl -v <Salesforce_Org_URL>/services/oauth2/token -d "grant_type=password" -d "client_id=*CLIENT_ID_GOES_HERE*" -d "client_secret= *CLIENT_SECRET_GOES_HERE*" -d "username=*[email protected]*" -d "password= *your_password_goes_here+*"
*The above command should provide you the access_token in a JSON formatted response. If you are running this command from an IP address that is outside of the trusted IP range specified by your connected app, you must append a security token to your password.
git clone https://github.com/forcedotcom/ApexUnit.git
This would create a local copy of the project for you.
mvn compile exec:java -Dexec.mainClass="com.sforce.cd.apexUnit.ApexUnitRunner"
-Dexec.args="-org.login.url $Salesforce_org_url
-org.username $username -org.password $password
-org.client.id $client_id
-org.client.secret $client_secret
-org.wide.code.coverage.threshold $Org_Wide_Code_Coverage_Percentage_Threshold
-team.code.coverage.threshold $team_Code_Coverage_Percentage_Threshold
-regex.for.selecting.source.classes.for.code.coverage.computation
$regex_For_Apex_Classes_To_Compute_Code_Coverage
-regex.for.selecting.test.classes.to.execute $regex_For_Apex_Test_Classes_To_Execute
-manifest.files.with.test.class.names.to.execute
$manifest_Files_For_Apex_Test_Classes_To_Execute
-manifest.files.with.source.class.names.for.code.coverage.computation
$manifest_Files_For_Apex_Source_Classes_to_compute_code_coverage
-max.test.execution.time.threshold
$max_time_threshold_for_test_execution_to_abort"
-proxy.host
$prox_host
-proxy.port
$proxy_port
Please replace all $xyz with the values specific to your environment/project
Required parameters:
Optional Parameters:
Note: You must provide either of the (-regex.for.selecting.source.classes.for.code.coverage.computation OR -manifest.files.with.source.class.names.for.code.coverage.computation) AND either of -(regex.for.selecting.test.classes.to.execute OR -manifest.files.with.test.class.names.to.execute)
Sample command:
mvn compile exec:java -Dexec.mainClass="com.sforce.cd.apexUnit.ApexUnitRunner" -Dexec.args=" -org.login.url https://na14.salesforce.com -org.username [email protected] -org.password yourpassword-org.wide.code.coverage.threshold 75 -team.code.coverage.threshold 80 -org.client.id CLIENT_ID_FROM_CONNECTED_APP -org.client.secret CLIENT_SECRET_FROM_CONNECTED_APP -regex.for.selecting.test.classes.to.execute your_regular_exp1_for_test_classes,your_regular_exp2_for_test_classes -regex.for.selecting.source.classes.for.code.coverage.computation your_regular_exp1_for_source_classes,your_regular_exp2_for_source_classes -manifest.files.with.test.class.names.to.execute ManifestFile.txt -manifest.files.with.source.class.names.for.code.coverage.computation ClassManifestFile.txt -max.test.execution.time.threshold 10 -proxy.host your.proxy-if-required.net -proxy.port 8080"
Note: Multiple comma separated manifest files and regexes can be provided. Please do not include spaces while providing multiple regex or manifest files.
On successful completion - the command should indicate that your build succeeded and should generate two report files - ApexUnitReport.xml (This is the test report in JUnit format) and Report/ApexUnitReport.html (This is the code coverage report in html format)
You can populate class names in the Manifest file and/or provide regular expressions(regexes) Please refer https://github.com/forcedotcom/ApexUnit/wiki/Manifest-file-vs-regex for the usecases where manifest file(s) and regex(es) option can be used
#Addional options
Use src/main/resources/config.properties to set the below parameters.
API_VERSION(Default value: 37.0) : The Partner API version in use for the org.
MAX_TIME_OUT_IN_MS(Default value : 1200000 ==> 20 minutes) : Time out setting for the session, Once timeout occurs, session renewer module is invoked which renews the session. Helpful when you face a connection exception during query executions.
CI engines like Jenkins(https://jenkins-ci.org/) can be used to seamlessly integrate ApexUnit with CI pipelines. Please find the details here: https://github.com/forcedotcom/ApexUnit/wiki/Integrating-with-CI-pipeline
https://github.com/forcedotcom/ApexUnit/wiki/Contribution-and-Bug-Issue-tracking