This article is a synopsis of the book " Unit Testing Principles ".
Let's start by listing the properties of good unit tests.
First. Integrated into the development cycle. Only those tests that you actively use are useful; otherwise it makes no sense to write them.
Second. Only the most important parts of your code are tested. Not all working code deserves the same attention.
Third. Provide maximum protection against bugs with minimum maintenance costs. To do this, you need to be able to recognize effective tests and write them.
However, recognizing and writing an effective test are two different skills. And to acquire the second skill, you must first master the first. The rest of this article will show you how to recognize an effective test. The pyramid of testing and testing according to the "black box" / "white box" principle will also be considered.
Four Aspects of Good Unit Tests
A good unit test should have the following attributes: bug protection, refactoring resistance, fast feedback, and ease of maintenance.
These four attributes are fundamental. They can be used to analyze any automated tests, be they unit tests, integration tests, or end-to-end tests.
Let's start with the first attribute of a good unit test: bug protection. A bug (or regression) is a software bug. As a rule, such errors occur after making changes to the code.
The more functionality, the higher the likelihood that you will add a bug to the new version. This is why it is so important to develop good bug protection. Without such protection, it will be impossible or very difficult to ensure the growth of the project in the long term due to the constantly increasing number of errors.
To assess how well a test performs in terms of bug protection, consider the following:
the amount of code executed by the test;
the complexity of this code;
the importance of this code in terms of business logic.
, , . , (assertions).
, -. , -, โ .
, . - -.
- โ . , .
. : . โ .
. : , , . , , . , .
? . - . , .
:
, . . .
. -, . , .
?
, , . , . : . โ , , .
โ , . , , . โ , .
- ( ) . , . - : , .
, . ( ), , ( ).
, , , : ( ).
, , . : . . โ II .
, : , . . .
: , . :
( , );
( , ).
. 3, . โ (), . โ (), .
:
-. , . . , , , .
. :
. . , .
. , , .
. ยซยป : , .
, . , .
? , . , โ , โ . : .
, . , . , , .
โ (end-to-end) . . , , .
, . , , , . - , .
: . , , . .
โ . , .
, . , , . - , .
- , , . : , .
โ โ , (end-to-end) . - , . . , .
. ; . , . , , . .
, ; . .
? : , . . , . , .
- CAP. , : (consistency) , (availability), (partition tolerance).
:
1. CAP ;
2. . โ , , - Amazon โ . .
: -, , .
. . , . , . . , .
. : ; - โ ; - .
, โ . : . , .
. - , -, โ . ; , , (, ). CRUD- - .
โ API, (, ). . , . , โ .
ยซ ยป ยซ ยป
ยซ ยป . . , , , .
ยซ ยป . . , .
, : , . ยซ ยป. โ , -, โ ยซ ยป , -. -, .
-
-
What is integration testing for?