Test Slack Apps
Write unit tests to verify whether your Apex code is working properly. Unit tests are class methods that don't take arguments or commit data to the database.
Slack app testing includes several files.
- The Apex class to be tested
- The Apex unit tests
ApexClass
metadata fileApexTestSuite
metadata file
In your SFDX project, create an Apex unit test in the classes
folder.
Create a test class and annotate it with @isTest
. Similarly, annotate your class methods with @isTest
.
Name your test class using the format TestYourActionName
, like TestAppHomeOpened
or TestCreateRecordDispatcher
.
Declare your test harness variables to store the Slack state and user session. To set up your test harness and simulate user interactions, use the Slack.TestHarness class.
For more information, see Testing Examples.
The ApexClass metadata file represents an Apex class, which you include for each test class.
TestMyAction.cls-meta.xml:
The ApexTestSuite metadata file represents a suite of Apex test classes to include in a test run.
MyActionTestSuite.testSuite-meta.xml: