Let's take a break from the testing process. Interviews can be unpredictable. Many testers, both manual and automated, have faced a surprising question during interviews: "Are you familiar with the testing pyramid?" You may wonder what API testing, test documentation, or application optimisation have to do with it; here's where we find out.
Testing pyramid
Test pyramid is a framework that helps testers decide where to focus their efforts. Each level of the pyramid has a different purpose and is important for making sure the software is of good quality. The main goal is to find the best mix of manual and automatic testing to create strong and dependable software.
The pyramid has three layers: unit tests at the bottom, followed by integration tests, and finishing with end-to-end tests at the top. Each level has a distinct role.
If you're testing a software application, like a marketplace website, you should have a planned method. Ideally, different people with their own skills would do each type of test.
At the bottom of the pyramid are unit tests. Unit tests look at the smallest parts of code, usually single functions or methods. They're great for finding issues early on and making sure each part of the code works right. In our marketplace example, unit tests might check that the function for adding a product to the cart or figuring out the total price works well. Developers often write and run these tests because they know the code best. They make sure each function or method does what it's supposed to do.
Moving up, you find integration tests. These tests check that different parts of the system work together well. For our marketplace, this might mean making sure that the product catalog, user login, and payment processes all work together without problems. Integration tests are key for finding any issues in how components talk to each other or fit together. Developers can write these tests to check the components' integration, and QA engineers can make more detailed test scenarios.
At the top are end-to-end tests. These tests act like real users to check the whole system. They go through different pages, use various features, and make sure the marketplace website works as a whole. End-to-end tests can find issues that come up from the way different parts work together or how users move through the website. These tests can be both manual and automatic.
It's also important to mention that there are several "postulates" on the real value and use of the pyramid.
Balance. The shape of the pyramid shows the perfect balance, with most tests at the bottom for unit tests, fewer in the middle for integration tests, and the least at the top for end-to-end or UI tests. This balance helps make the most of testing time and resources. Why is this good? Because unit tests are:
1. Quick to make.
2. Passed fast.
3. Don't need a separate test team (made by the developers).
4. Find issues quickly at a basic level, which stops more complex problems.
5. Make sure the code works at a basic level.Automation is very important in pyramid testing. Automatic tests are key for being efficient and quick in testing. By making repetitive and time-taking tests automatic, you free up people to work on more complicated tests. Plus, automation gives quick feedback and helps with continuous work and delivery, which are important for agile development.
Speed. Fast and trustworthy tests are what pyramid testing focuses on. Unit tests are at the bottom and give quick feedback about how well separate parts work. They help find problems early, which is easier and cheaper to fix. Tests get slower as you go higher because they're more complex, but they check more functions. Finding the right speed and range of what you're testing is key for good testing.
Coverage. Coverage is very important in pyramid testing. The pyramid shape tells us to cover a lot with unit tests at the base and less with UI tests at the top. With this strategy, you can find bugs at different levels and lower the chance of faulty software being released.
Risks. Even though the pyramid strategy helps lower costs and is efficient, it doesn't get rid of all the risks. UI tests, for example, can be fragile and might need fixing if the UI changes and breaks the tests. Also, just using unit tests could make you miss problems with how things work together. It's important to balance and use different tests to handle these risks in the best way.
Place of API in the testing pyramid
APIs allow you to do integration tests to check that different parts of your software work well together. They also help you do end-to-end tests to make sure the whole system works correctly. API tests are a kind of integration test.
Imagine there's a marketplace website. You need to do integration tests to check that its parts work well together. Testing the APIs, you can make sure that data is shared correctly between the parts. This involves checking that requests and responses are right, making sure the shared information is accurate and dependable.
Going higher in the testing pyramid to end-to-end testing, where UI tests are done, you check the website from the user's side. This includes tasks like adding items to the cart or paying. APIs manage the work that happens out of sight. For instance, when a user puts an item in the cart, the API deals with the request, updates what's in stock behind the scenes, and adds up the total cost for the chosen items. Testing APIs in end-to-end tests makes sure that the key business functions are correct. You check that data is processed right and that the system works as it should.
APIs are crucial for both integration and end-to-end testing when you test websites. Doing API testing helps ensure that different parts of a website work well together and checks that the whole system is functional. By including API testing in your test strategy, you can improve the software quality and make sure users have a good experience, whether they are buying or selling.
Backend
Backend refers to the services hosted on servers. These servers often run on Linux, which is a key operating system in the backend.
Linux is the preferred choice for hosting backend services because it provides a strong and safe environment that protects user data. Linux also delivers great performance and stability, which helps websites manage high traffic and offer users a smooth experience. Additionally, Linux servers are highly scalable, making it easy to add resources as the website grows. You will learn more about this in future topics.
For example, as a tester, your main job is to check that all backend services work properly and the website runs smoothly.
API testing. Begin by focusing on API testing, which tests how different parts of the marketplace website interact. This includes testing the endpoints that allow the frontend and backend to communicate. Here, you'll make sure that data is sent correctly, responses arrive quickly, and any mistakes or issues are dealt with well.
Database testing. Then, test the database behind the marketplace website. You'll check that the data is stored, accessed, and updated correctly. You'll also make sure that the database follows the set layout and any rules or checks are applied right.
Performance testing. With this testing, you'll look at the system's response times, ability to handle data, and resource use under different amounts of traffic. This helps you find any problems and improve the backend's performance as user numbers grow.
Security testing. You must do security testing to find possible weak spots and make sure the backend is secured against common dangers. This includes ensuring proper access control, encryption of private data, and protection against widespread attacks like SQL injection and cross-site scripting (XSS).
Also, testing how the backend deals with errors is crucial. For example, you might add a product with an invalid ID to the cart and see if the backend recognises and manages the error well.
The link between the testing pyramid and the backend is that the backend usually includes the business logic and data handling of an application. Unit tests, which are the base of the testing pyramid, are closely tied to backend development. These tests focus on checking single units of code by themselves, such as functions, methods, or classes, to make sure they work right. They help ensure the backend parts act as expected in different situations and give quick, trustworthy feedback.
Conclusion
There is a modern alternative to pyramid testing: the testing trophy from Kent Dots. According to this theory, tests are divided into four levels; that's a special task for you to explore.
There is also an interesting model called testing honeycomb from Spotify. It works well for testing microservice products, where the key focus is on the integration between services.
So dear testers, you are now one step closer to successfully landing an offer. Let's not stop here; let's keep going!