Shift Left Testing: What It Means and Why It Matters
By Shreya Bose, Technical Content Writer at BrowserStack - December 17, 2020
What is Shift Left Testing?
Think of traditional software development models for a second. Here’s what they usually look like:
Testing enters the picture at the very end or to the extreme right of the pipeline. Shift Left Testing literally pushes testing to the “left,” i.e., to earlier stages in the pipeline. The Shift Left approach intends to identify and resolve bugs as early as possible in the development process. This improves software quality and reduces time spent in resolving issues (which usually magnifies as development progress) later in the pipeline.
In practical terms, this translates to more tests being run by developers themselves before they push their individual code unit to version control. There are a number of tests every developer should run to contribute to the success of Shift Left Testing and push better products.
Why Adopt a Shift Left Strategy?
When testing is paused until the end of development, any bugs that do show up will usually be more difficult to fix. Their resolution needs the software to be reworked in its entirety since all the code has already been created. Consequences of such an approach would be:
- Increase in cost, since the software needs to be sent back and reworked from scratch
- Increased time to market, since such reworks will take longer to complete
When it comes to fixing bugs, the earlier the cheaper. According to the NIST, resolving defects in production can cost 30 times more and up to 60 times more in case of security defects.
The Shift Left Testing approach implements a process that lets developers detect bugs early and often. Bugs identified when code is being written or reviewed by devs are the easiest to fix, because these code units are small and infinitely more manageable. Once merged into the main development branch, the breadth of code widens, and so does the effort required to find anomalies within it.
Main Benefits of Shift Left Testing
- Lower costs. As explained above, bugs detected earlier are cheaper to fix.
- Increased efficiency in the software development process.
- Improved product quality because more bugs are detected in earlier stages.
- Reduced time to market since the QA process doesn’t take as much time.
- Offers a competitive advantage by letting development teams move fast, build and defend their credibility by innovating in iterations.
How to Implement Shift Left Testing Approach?
- Bring developers into testing activities: When developers test their code before pushing it to the main branch, the merged code is cleaner and less error-prone. Individual code units are easier to test because they are smaller and more navigable.
- Introduce testers to coding: Agile in its best avatar (which is usually synonymous with DevOps) requires developers to test and testers to code. Obviously, neither is expected to be an expert at something that is not their primary domain. But devs should be able to run intermediate-level tests, and QAs should know enough coding to implement some quick fixes wherever possible. Basic coding skills help testers be effective at code reviews and enable them to be valuable contributors in sprint teams. Testers need to be proficient enough to be able to read and modify simple code – such as an automated test or rework fundamental methods.
- Include testers early on: Shift Left Test in Agile works best when QAs come in from the first brainstorming session. When developers throw around ideas on how to build a website or app, QAs must be present. This helps them understand the fundamental concepts, allowing them to design better tests for the Continuous Testing stage. Additionally, having QAs in the room can give devs a clear image of what bugs would be likely to emerge and how they can be avoided. Successful DevOps hinges on automation. QAs need to know how the code is being shaped and what is expected of the final product to create relevant test cases. They cannot be expected to comb through every line of code, looking for every semicolon out of place. Additionally, when devs run tests on their code, they might need input from QAs who can guide them on what to check for.
- Keep testability in mind while coding: Like everything in Agile processes and DevOps, collaboration is the key to success. Successful Shift Left Testing also requires a team effort. It can’t be something done only at the end of a sprint by particular individuals (designated testers). When writing code, developers should ask themselves “How do I make it more testable?” This might mean exposing a hook or creating a unique ID for an element. Additionally, this way of thinking makes developers aware of issues that can break functionality or cause operational issues. When software is created with its suitability for testing in mind, Shift Left Testing becomes far more effortless.
Best Practices for Shift-Left Testing in Agile
- Plan for it: Shape development in a way that is friendly to Shift Left Testing. Once requirements have been established, devs and testers should ideate on how to shape coding and testing as early and incrementally as possible. Depending on product expectations as well as the limitations of the team, specific strategies might have to be crafted to accommodate the Shift Left approach.
- Use Static Code Analysis: Static code analysis is the practice of checking the code without executing it. It runs through the basic code structure and ensures that the code is aligned with a number of standards and guidelines. Generally, the static analysis looks for the following issues:
- Programming errors
- Violations of commonly followed coding standards
- Syntax anomalies
- Security issues
Static code analysis is best done via automation; otherwise, it is impossibly tedious. The software should scan all untested code in a project before it moves to QA. A static code analyzer checks code against a set of predefined standards and rules to determine if the code complies with them.
If the analyzer does flag any issues, a human developer/tester will have to examine them to verify that they are not false positives. Then, devs can fix apparent mistakes and send the code to testers.
- Offer continuous feedback: As far as possible, devs and testers should be offered feedback across the software lifecycle. This lets gaps be addressed immediately and offer everyone involved a better perspective on any major trends popping up during testing. It can also help them with future projects, especially ones that would be similar to the current one.
- Specify Quality Standards: Remember that devs are not usually trained in testing from scratch. Therefore, they cannot be expected to intuitively figure out the finer points of testing. QAs and QA managers should outline the level of quality, performance and operational success expected from the code so that devs running tests know what bugs to look for. They need to have a clear idea of what may be non-negotiable and what issues can be forwarded to QAs (preferably with a few lines of context). Clarity on quality standards also helps tests apply the right kind of rigour to ferret out bugs in their own code.
The Role of Real Device in Shift Left Testing
All tests, starting from developer testing must be conducted on real devices. Software testing can only be effective when tests are being run in real user conditions. Running tests on emulators or simulators cannot provide 100% accurate results, and therefore developers won’t be able to evaluate the quality of their code adequately. Any results yielding from tests on emulators or simulators would be only partially correct, and thus development activities based on these results will not ensure high-quality software.
Whether manual testing or automated Selenium testing, real devices are non-negotiable in the testing equation. In the absence of an in-house device lab (that is regularly updated with new devices and maintains each of them at the highest levels of functionality), opt for cloud-based testing infrastructure. BrowserStack provides 2000+ real browsers and devices that can be accessed for testing from anywhere in the world at any time.
Users can sign up, select a device-browser-OS combination, and start testing for free. They can simulate user conditions such as low network and battery, changes in location (both local and global changes), and viewport sizes as well as screen resolutions.
By running tests on a real device cloud, Shift Left Testing can be conducted with the assurance that they are getting accurate results every time. Comprehensive and error-free testing, starting at dev-level prevents bugs from showing up (usually magnified) at later stages, which reduces the time and effort required to handle them. It is almost always easier to fix the bugs that devs discover before pushing code. It also allows the software to hit the market faster and reduces the possibility of lost revenue and credibility due to entirely avoidable bugs.