Testing - Chapter 11-14 in SWE at Google (Edition 2)
作者:互联网
Testing Overview
Why to test?
Chapter 11 gives some reasons:
- Find bugs early.
- An equally important reason why you want to test your software is to support the ability to change. (change software with confidence)
- The act of writing tests also improves the design of your systems. As the first clients of your code, a test can tell you much about your design choices. If new code is difficult to test, it is often because the code being tested has too many responsibilities or difficult-to-manage dependencies.
- Improved documentation, good test suite are good documentation.
- Simpler reviews
- Teams can release new versions of their application with confidence.
What is a test?
- A single behavior you are testing, usually a method or API that you are calling
- A specific input, some value that you pass to the API
- An observable output or behavior
- A controlled environment such as a single isolated process
Attention: A bad test suite can be worse than no test suite at all.
Story: GWS (Google web server)
Releases were becoming buggier, and it was taking longer and longer to push them out. Team members had little confidence when making changes to the service, and often found out something was wrong only when features stopped working in production.
To address these problems, the tech lead (TL) of GWS decided to institute a policy of engineer-driven, automated testing. Within a year of instituting this policy, the number of emergency pushes dropped by half.
Design a Test Suite
Image followed is the difference of small, medium and large size of a test.
Small tests must run in a single process. Cannot run a third-party program such like a database. Also, they are not allowed to sleep, perform I/O operations, or make any blocking calls. They are not allowed to access the network or disk (not strictly denied here).
The only remaining restriction is that medium tests aren’t allowed to make network calls to any system other than localhost. As we all know that the amount of unit level test is 80%, integration test is 15% and end-to-end test is 5%.
Testing at Google scale
- Store almost every line of code in a single monolithic repo(monorepo https://semaphoreci.com/blog/what-is-monorepo)
- No repo branching. Manage testing at this scale by using of a CI system. Key component: Test Automation Platform(TAP).
- Each supported language at Google has one standard test framework and one standard mocking/stubbing library.
Fast testing
- Avoid sleep() and timeout(), instead, using polling for a state transition with a frequency closer to microseconds.
- The secret to living with a large test suite is to treat it with respect. Treat tests like production code.
- Using techniques like parallelizing execution and using faster hardware.
标签:Chapter,11,tests,Google,testing,code,test,suite,your 来源: https://www.cnblogs.com/Sanhao99/p/16345716.html