Functional Testing on the Cloud: 12 Ways to Do it Better
Functional Testing on the Cloud: 12 Ways to Do it Better
Learn how to do functional testing on the cloud, the right way.
Join the DZone community and get the full member experience.Join For Free
A good automated test suite gives actionable feedback, helps fix bugs faster, and enables rapid delivery of software. A good automated test suite on the cloud does it more cost-efficiently. But more often than not, functional testing on the cloud ends up delaying feedback, increasing flakiness, and providing zero visibility into the failures—results that are completely at odds with initial expectations. It ends up hampering the pace of rapid delivery lifecycle.
You may also enjoy: How is Functional Testing Affected by Cloud Automation?
To truly make the most of functional testing on the cloud, you have to reconsider the testing practices you follow. At BrowserStack, we help thousands of customers run functional test suites on the cloud every month. Our QA and Support teams identified certain practices that, when applied, can help teams of all sizes get better builds in less time.
Here they are, compiled into a 3-part, 12-step guide for better functional testing on the cloud. Most of it has to do with feasible changes you can make in the setup, the test suites, and the solutions provider.
Part 1: The Setup
Architectures and system setups change depending on what you're optimizing for. 9 times out of 10, you'll be optimizing for speed, stability, costs, etc. These are not mutually exclusive.
A stable, cost-efficient test setup will let you:
- run tests faster,
- re-run tests faste, whether it's a single test (for identifying flaky scripts) or entire suites after a bug fix,
- reduce flakiness,
- easily identify buggy commits, and
- scale with your tests, projects, and teams.
Here's how you can optimize your setup so it meets those requirements.
1. Target an Acceptable Test Execution Time
The idea is to get quality builds, faster, but it's a balancing act: you have to run the optimum number of tests in a reasonably short duration of time. Ten minutes is the general norm for BrowserStack users, but it can vary depending on your testing strategy.
Aim to finish all automated tests within the targeted test execution time. This helps you plan better and identify unexpected failures (or flakiness) in the test setup.
2. Run Your Tests on Every Pull Request (If Not After Every Commit)
If your tests don't take forever to run, you are free to run them more often.
Cloud testing platforms charge you on the basis of your parallelization requirements (i.e., the ability to run a number of tests at the same time), and not the frequency of their usage.
To isolate bugs early in the lifecycle, run tests after every commit. This can get overwhelming, so an alternative is to run tests on every pull request.
The aim is to spread out your testing throughout the release cycle and avoid a bottleneck towards the end.
3. Configure Your CI for Efficiency
You will want to reconsider your CI setup depending on your team's requirements, the frequency of testing, the projects you test in parallel, and the number of tests you intend to run. Most teams use a master-slave configuration in CI so that the master machine handles dispatching jobs, monitoring those jobs, and reporting the results. This is because a lot of jobs make the CI machine busy and unresponsive, leading to slow and flaky tests.
Lastly, ensure your machine can handle the number of requests that your tests make when they're run in parallel.
Note: Network latency between your CI machine and your cloud testing platform can be minimized if your cloud vendor's data centers are close to you, geologically speaking.
Part 2: The Test Suites
Tests that run blazing fast on your workstation/device often take exponentially longer to run on the cloud. This is expected due to factors like network latency between your machines and testing platform, browser setup (or device startup) time, your webpage loading latencies, etc.
There are a few things that you can do to speed up your tests considerably, despite those factors.
4. Keep the Tests Short
Keeping the tests short not only leads to fast execution times but also makes them less flaky (and easier to iterate or fix later). Here's what we suggest:
- Avoid testing (and re-testing) elements that you don't need to test (and re-test).
- Use Selenium requests sparingly. Each request increases your test execution time. (For instance, instead of an if-else condition to loop request until an
elementIDis received, try explicit wait).
- If the test case can be split into a bunch of smaller ones, split it.
5. Embrace Parallelization
Instead of lining them up to run one after the other (sequentially), run your tests concurrently with parallelization.
Most modern testing frameworks and cloud solutions support this out-of-the-box. For instance, if you have a test script that tests 20 invalid inputs, split it into 20 smaller scripts and run them all at once.
6. Optimize to Prevent Queuing
Most cloud testing platforms set soft limits on their browsers and devices to meet the demand at peak times, prevent abuse, and avoid denial of service attacks. Once you hit these limits, your tests will be queued to run after the current tests are done.
To avoid hitting those soft limits, start "blending."
Blending is basically distributing your tests between the browsers — so more tests run in parallel without hitting the soft limit on any one browser.
So, if you have 100 tests that to be run on Chrome, Firefox, and IE each, and a soft limit of 80 tests per browser type, you'll be able to run 80 tests on a browser and the remaining 20 will be queued.
To avoid the queue, you can run the first 50 tests on Chrome and Firefox at once. Once they're done, run the remaining 50 tests on Chrome and Firefox.
7. Use Built-In Debugging Options
Cloud vendors offer built-in debugging assistance — such as screenshots at every request (or every failure), video recordings of the test session, Selenium logs, network logs, etc. Instead of writing your own code and logic for taking screenshots and saving it locally, use those features. Tip: Where possible, organize your tests into builds and projects and label them appropriately. If a test suite fails, this would make it easier to isolate the bug to a build and debug faster.
Part 3: The (Cloud) Solution Provider
Cloud gives you access to more browsers (types and versions) than your local workstation could handle. It's instantly scalable and has no maintenance requirements. The trade-off for cost-efficient, on-demand scalability, however, is network latency.
To be confident of the code quality and functionality, there are ways to test smartly on the cloud. Here are some suggestions.
8. Test on The Right Browsers and Devices
Developers write code for and test on the latest version of Chrome. Now, this would be enough if all of your end-users are on the latest version of Chrome. But you'll have to do your cross-browser testing across browsers and versions
- that are favored by your end-users,
- that have the highest usage trends in your target markets/countries at a given time,
- that are correlated with large drops in the conversion funnel (payments or signups, etc.),
Prioritize your testing on these browsers, instead of every browser available on the cloud platform.
If you have enough parallel threads / concurrent slots with your cloud vendor, you can look at testing on additional browsers and versions without overshooting your targeted test completion time.
9. Test on Different Screen Sizes
A product built for developers' use should not break on those huge monitors developers are fond of.
Your front-end developers spent a considerable amount of time adapting your website to different resolutions. It'd be a waste NOT to test them on different screen sizes. If you expect your users to view your application on different screen sizes and resolutions, be sure to test your responsive design.
10. Test on Right Mobile Devices
Cloud platforms will have plenty of real mobile devices you can test on. At BrowserStack alone, we have over 2000 iOS and Android devices. That doesn't mean you have to test on every last one of them. Just like with browsers and versions, find the mobile devices popular in your target market at a given time. Refer to this resource to find the right devices to test on.
11. Run Tests in Real User Conditions
A lot of top-of-the-funnel conversions (like signups) take place on mobile. For eCommerce, over 40% of purchases are made through mobile devices. A buggy mobile app can — and will — directly affect your revenue. Test a mobile app in real-world conditions. Create variables like timezones, IP addresses and locations, network speeds, etc. to mimic the environment your target audience is in.
12. Set up Alerting, Monitoring, and Bug Tracking
Instead of waiting around until the tests are done running, you can set-up real-time alerts to get notified exactly when and where your test/build failed. You can do this with a webhook from your CI machine or your cloud testing platform (or their REST APIs) to get the status of your test runs and set up notifications for yourself and your team. (We have a Slack integration for that, and more are in the works). You can streamline your workflows further by integrating your cloud platform with your bug filing tool. These would automatically create tasks in your bug tracking tools — and populate them with all the data developers will need to recreate and fix. And if your setup tracks the bugs back to specific commits, you'll know who to assign it to.
Automated functional testing can be a pain. Functional testing on the cloud can be a pain, but with an added sting of network latency. This blog post lists some easy optimizations that'd help you not just test better, but also make the most of your cloud testing platform.
You can run your functional tests on the Cloud without the hassle of exposing your local servers to public URLs. Join us for a free webinar on November 6, 2019, to learn how to test at scale within your internal networks.
Published at DZone with permission of Payal Dinodia . See the original article here.
Opinions expressed by DZone contributors are their own.