Running Tests
November 6, 2024 ยท View on GitHub
There are two test environments for the Twilio connector. The default test environment is the mock server for Twilio API. The other test environment is the actual Twilio API. You can run the tests in either of these environments and each has its own compatible set of tests.
| Test Groups | Environment |
|---|---|
| mock_tests | Mock server for Twilio API (Defualt Environment) |
| live_tests | Twilio API |
Running Tests in the Mock Server
To execute the tests on the mock server, ensure that the IS_TEST_ON_LIVE_SERVER environment variable is either set to false or unset before initiating the tests. This environment variable can be configured within the Config.toml file located in the tests directory or specified as an environmental variable.
Using a Config.toml File
Create a Config.toml file in the tests directory and add your authentication credentials and phone number for the authorized user:
isTestOnLiveServer = false
Using Environment Variables
Alternatively, you can set your authentication credentials as environment variables:
export IS_TEST_ON_LIVE_SERVER=false
Then, run the following command to run the tests:
./gradlew clean test
Running Tests Against Twilio API
Prerequisites
To run the tests, you need Twilio account credentials, a Twilio phone number and a test phone number. To get Twilio account credentials and Twilio phone number;
-
Create a Twilio account.
-
Obtain a Twilio phone number.
Tip: If you are using a trial account, you may need to verify your recipients' phone numbers before initiating any communication with them.
-
Obtain a Twilio Account Auth Token.
Now, you can set Twilio credentials and phone numbers either in a Config.toml file in the tests directory or as environment variables.
Using a Config.toml File
Create a Config.toml file in the tests directory and add your authentication credentials and phone number for the authorized user:
isTestOnLiveServer = true
accountSid="<your-twilio-account-sid>"
authToken="<your-twilio-auth-token>"
toPhoneNumber="<your-test-phone-number>"
fromPhoneNumber="<your-twilio-phone-number>"
apiKey="<your-twilio-api-key>"
apiSecret="<your-twilio-api-secret>"
Using Environment Variables
Alternatively, you can set your authentication credentials as environment variables:
export IS_TEST_ON_LIVE_SERVER=true
export ACCOUNT_SID="<your-twilio-account-sid>"
export AUTH_TOKEN="<your-twilio-auth-token>"
export TO_PHONE="<your-test-phone-number>"
export TWILIO_PHONE="<your-twilio-phone-number>"
export API_KEY="<your-twilio-api-key>"
export API_SECRET="<your-twilio-api-secret>"
Then, run the following command to run the tests:
./gradlew clean test -Pgroups="live_tests"