FIRST Rules (Fast, Independent, Repeatable, self-validating, Timely)
Unit testing is probably familiar, even if you haven’t actually done it, but you’ve certainly heard about it and its importance. A complete and standardized unit test can not only help you write concise code, make the code become extensible, maintainable, reusable, but also greatly improve the robustness of the code.
1. The three laws of TDD
-
1. Do not write production code until you have written unit tests that pass
-
2. Write only unit tests that just fail, and fail to compile
-
3. Write only production code that is just enough to pass the current failing test
Tests are written with production code, only a few seconds before the production code. Write the program this way, and the tests will cover all production code. The amount of test code can rival the amount of production code, leading to daunting management problems.
2. Keep your tests clean
-
1. Dirty tests are the same as no tests. Tests must be changed as production code evolves, and the dirtier the test, the harder it is to change
-
2. Test code is just as important as production code. It needs to be thought about, designed, and cared for, and it needs to be kept as clean as production code
-
3. If tests are not kept clean, you lose them. Without tests, you lose everything that makes your production code extensible
3. Clean tests
Here the author follows the principle of saying important things three times: readability, readability, readability. The way to make it readable is to make sure that your test code is as clear, concise, and expressive as any other code, which is something that this book has always emphasized.
The sample (The example code) : Is case
The code above is a build-operate-check mode, where the first part constructs the test data, the second part manipulates the test data, and the third part verifies that the operation has the desired result
4. Test one assertion per test
-
1. Each test function in JUnit should have one and only one assertion statement
-
2. It is best to say that the number of assertions in a single test should be minimized
-
3. The best rule is that you should minimize the number of assertions per concept and only test one concept per test function
5.F.I.R.S.T
- 1. Fast tests should be Fast enough
- 例 句 : Tests should be Independent of each other
- Repeatable test shall be Repeatable in any environment
- 4. Tests should have Boolean output, and if tests cannot be validated independently, the determination of failure becomes subjective.
- Tests should be written in time. Again, tests are written only a few seconds before production code.
6. References
The way of clean code www.jianshu.com/p/0479b3ad7… www.jianshu.com/p/c44eca6ad…
Pay attention to the public account “Programmer interview”
Reply to “interview” to get interview package!!
This public account to share their own from programmer xiao Bai to experience spring recruitment autumn recruitment cut more than 10 offer interview written test experience, including [Java], [operating system], [computer network], [design mode], [data structure and algorithm], [Dacheng face by], [database] look forward to you join!!
1. Computer network —- Three times shake hands four times wave hands
2. Dream come true —– Project self-introduction
Here are the design patterns you asked for
4. Shocked! Check out this programmer interview manual!!
5. Teach you the interview “Profile” word for word
6. Nearly 30 interviews shared