Use 'flavors' to run the best tests for an environment

2 minute read

Capturing test reports and selecting tests to run in multiple environments (for example, browser tests, mobile tests, etc.)

Lots of teams run the same tests across several different environments. For example, a UI test suite might be run in several browsers in parallel. Or perhaps you need to build a slightly different version of a mobile app for different locales and need to run the same tests across all of them.

In these scenarios, a test result is not just a test result: it is the combination of the test and the environment that it was run in. A test might pass in one environment but fail in another.

Cloudbees Smart Tests supports these scenarios with a concept called flavors .

Flavors
Figure 1. Flavors

--flavor is set once, as key-value pairs, when you create the test session with smart-tests record session. (You can submit multiple key-value pairs, too: --flavor key=value --flavor key2=value2 .) smart-tests subset and smart-tests record tests don’t take a --flavor option themselves — every test recorded or subsetted through a session automatically carries that session’s flavor, so create one session per flavor and reference it with --session for every step of that flavor’s run.

For example, reporting results for two flavors, with no subsetting yet:

# one session per flavor smart-tests record session --build [BUILD NAME] --test-suite [TEST SUITE NAME] --flavor browser=chrome > session-chrome.txt smart-tests record session --build [BUILD NAME] --test-suite [TEST SUITE NAME] --flavor browser=firefox > session-firefox.txt # run tests in Chrome and report results cypress run --reporter junit --reporter-options "mochaFile=report/test-output-chrome.xml" smart-tests record tests cypress --session @session-chrome.txt report/test-output-chrome.xml # run tests in Firefox and report results cypress run --reporter junit --reporter-options "mochaFile=report/test-output-firefox.xml" smart-tests record tests cypress --session @session-firefox.txt report/test-output-firefox.xml
▼

Later, when you want to request a subset of tests, request it against the flavor’s session — the subset will automatically be scoped to that flavor.

For example:

# one session per flavor smart-tests record session --build [BUILD NAME] --test-suite [TEST SUITE NAME] --flavor browser=chrome > session-chrome.txt smart-tests record session --build [BUILD NAME] --test-suite [TEST SUITE NAME] --flavor browser=firefox > session-firefox.txt # get a subset for Chrome, run it, then report results find ./cypress/integration | smart-tests subset cypress --session @session-chrome.txt --confidence 90% > subset-chrome.txt cypress run --spec "$(cat subset-chrome.txt)" --reporter junit --reporter-options "mochaFile=report/test-output-chrome.xml" smart-tests record tests cypress --session @session-chrome.txt report/test-output-chrome.xml # get a subset for Firefox, run it, then report results find ./cypress/integration | smart-tests subset cypress --session @session-firefox.txt --confidence 90% > subset-firefox.txt cypress run --spec "$(cat subset-firefox.txt)" --reporter junit --reporter-options "mochaFile=report/test-output-firefox.xml" smart-tests record tests cypress --session @session-firefox.txt report/test-output-firefox.xml
▼

This feature lets you select the right tests to run based on the changes being tested and the environment they are being run in.