It's important to talk about the goal of testing. While it's significant to test that users can use your application (e.g.: "-I can log in", "-I can save an object") it is equally important to test that your system doesn't break when incorrect data or unexpected actions are performed. You need to anticipate what would happen when a user makes a typo, tries to save an incomplete form, or uses the wrong API. You need to check if someone can easily compromise data, get access to a resource they're not supposed to. A good testing suite should try to break your app and help understand its limit.
There are many different types of testing that you can use to make sure that changes to your code are working as expected. Not all testing is equal, though, and we will see here how the main testing practices differ from each other.
1.1. Pros and cons of testing
Pros:
- More reusable code and easier debugging.
- Reduce the cost of bug-fixing.
- Errors can be detected at the early stages.
- Increased efficiency of code improvement and maintenance.
- Tests help find problems and resolve them.
- Tests can check whether application does what was assumed in a first place (TDD based approach - tests firsts)
- Tests can serve as an API documentation - by looking at tests, other developers can learn how API really works.
Cons:
- The process of testing can be time-consuming.
- Not all errors can be detected.
2. Manual vs. automated testing
At a high level, we need to make the distinction between manual and automated tests. Manual testing is done in person, by clicking through the application or interacting with the software and APIs with the appropriate tooling. This is very expensive as it requires someone to set up an environment and execute the tests themselves, and it can be prone to human error as the tester might make typos or omit steps in the test script.
Automated tests, on the other hand, are performed by a machine that executes a test script that has been written in advance. These tests can vary a lot in complexity, from checking a single method in a class to making sure that performing a sequence of complex actions in the UI leads to the same results. It's much more robust and reliable than automated tests – but the quality of your automated tests depends on how well your test scripts have been written.
Automated testing is a key component of continuous integration and continuous delivery and it's a great way to scale your QA process as you add new features to your application. But there's still value in doing some manual testing with what is called exploratory testing as we will see in this guide.
3. Unit vs Integration tests
Unit tests are based on low level code, close to the source of your application. They consist of testing individual methods/functions/routines. Unit tests are in general quite cheap to automate and can be run very quickly by a continuous integration server. Additional benefit of Unit tests is that they can quickly locate regressions (bugs that were once fixed and show up again). Ideally, each and every bug that was found has its corresponding test that becomes a part of Unit testing framework.
Integration tests verify that different modules or services used by your application work well together. For example, it can be testing the interaction with the database or making sure that microservices work together as expected. These types of tests are more expensive to run as they require multiple parts of the application to be up and running.
1 Comment
Agata Filipczak
Okey, we have introduction to tests, but I would add some info about what is TDD actually, why we should code tests before source code etc right?