A simple, lightweight project that allows Salesforce Flows to run as Apex Unit tests.
- Install the package
- Write a flow that tests some piece of functionality and set the name to start with test_
- Add a decision to the end of the flow that checks if the automation ran as expected
- Create a text variable called Result, set it for output
- If the functionality ran as expected, set the output variable to 'Success'
- If the functionality didn't run as expected, set the output variable to an human readable error message.
- In setup, navigate to apex test execution, and run the DeclarativeTestRunner apex test
- If your functionality does not work as expected, one of the tests that are part of DeclarativeTestRunner will fail, with your error message.
- Create a record triggered flow that creates 5 accounts and inserts them.
- After the insert element, query accounts for the names of the new accounts
- Add a decision that checks your query returned 5 records
- Create an output text variable named 'Result'
- If the query returned 5 records, set the Result variable to "Success"
- If the query returned some other count of records, set the Result variable to a formula that shows the expected and actual count of records returned.
- Save the flow, and set the flow name to start with Test_
Note - you do not need to activate your flow, and it does not need to set up other automation to trigger it, the flow will be triggered automatically.
##Key Naming Conventions All testing flows must have:
- A name that start with test_
- An output text variable named Result that is set to 'Success' on passing criteria
See Wiki for further resources. See Issues for how you can help.
To work on this project in a scratch org:
- Set up CumulusCI
- Run
cci flow run dev_org --org dev
to deploy this project. - Run
cci org browser dev
to open the org in your browser.