当前位置:网站首页>TDD and automated testing
TDD and automated testing
2022-06-28 23:04:00 【Johns】
What is? TDD?
TDD Is a core practice and technology in agile development , It's also a design methodology .TDD The principle is before the development of functional code , Write unit test case code first , The test code determines what product code needs to be written .
Why TDD?
TDD The benefits of
- Reduce the burden on developers Through a clear process , Let's focus on one point at a time , Less burden on thinking .
- Protection network TDD The benefit is to cover full unit tests , It provides a protection net for product code , So that we can easily Meet demand changes or Improve code design . So if your project needs are stable , Do it all at once , If there is no change in the future , Can enjoy TDD The benefits are less .
- Clarify requirements in advance Writing tests first can help us think about requirements , And clarify the details of requirements in advance , Instead of finding ambiguous requirements halfway through the code .
- Quick feedback A lot of people say TDD when , My code volume has increased , So the development efficiency is reduced . however , If there is no unit test , You have to test by hand , You have to spend a lot of time preparing the data , Start the application , Jump interface, etc , Feedback is slow . Accurate said , Quick feedback is a benefit of unit testing .
TDD What matters is not the test code itself , It is the thinking of solving problems , TDD Drive us to be result oriented , Makes us simplify the design , Focus on delivering a stable stack of value streams .
TDD The ultimate goal is Produce clean and usable code
TDD What to do ?
TDD The three principles of
- Don't write any functional code before testing
- Write only one test that just failed at a time , As a description of the new function
- Don't write any extra product code , except ⾮ It just makes the failed test pass
meanwhile TDD Also follow the test FIRST principle
- F(Fast): The test should be able to run quickly
- I(Isolate): Test cases should be independent , Can't depend on each other
- R(Repeatable): The test should be repeatable
- S(Self-verifying): The test will check the output by itself
- T(Timely): The test should be done in time , And writing code
Background test type definitions
Test level | A0 | A1 | A2 | A3 |
|---|---|---|---|---|
Verification scope | Method 、 class | Integration between modules within the service | Single service interface | Multi service multi interface tandem scenario |
The upper limit of execution time for a single use case | <=1S | <=3S | <=10S | =1S It is recommended to control 10 Within minutes, |
stability | high | high | in | in |
Test case and tested object | In the same process / With the machine | In the same process / With the machine | Cross process / Same or different machine | Different machines cross process |
Network dependence | Do not rely on | It is recommended to rely on the local network | rely on | rely on |
Service dependence | Do not rely on | It is recommended to rely on local test avatars | It is recommended to rely on non substitutes | Rely on non substitutes |
Database dependency | Do not rely on | It is recommended to rely on the local database | Access the network database | Access the network database |
Execution network | DEV | DEV | IDC | IDC |
You need to deploy and start the tested object | Unwanted | Unwanted | need | need |
Test type | White box testing | White box testing | Black box testing | Black box testing |
Custom test type | Industry test types |
|---|---|
A0 | unit testing |
A1 | unit testing |
A2 | The interface test |
A3 | e2e test |
Test case specification
golang Test case specification
Case presentation
User mobile number password login service , See attachment list for details
See details of specific process : TDD Case actual combat
Automated integration
- Interface test automation can be used directly Yapi Automated testing solutions for go test -coverprofile=c.out ./... go tool cover -html=c.out -o coverage.html
- Unit tests can be executed in advance on the pipeline
common problem
Why do many people do TDD Can't do it ?
- The task will not be split properly TDD Split the task before , Break a big demand into several small ones .
- Can't write tests What are effective unit tests , A lot of people write tests , I don't even know what I'm testing , Or maybe there are no assertions , Output through console , Visual comparison to verify . Good unit tests should conform to simple , Fast , Contains assertions that can be repeated
- Can't write just the right implementation Many people can't focus on the current requirements when writing implementation , Accidentally realized other requirements , It destroys the sense of rhythm . When it comes to implementation, it won't take small steps .
- No refactoring I don't know what is Clean Code, I can't see Smell, Not refactored in time , It's hard to start when you want to refactor . I don't know how to use the right one 「 methods 」 eliminate Smell.
- Backward infrastructure For a particular technology stack , The unit test infrastructure is not built well , As a result, you can't focus on test cases when writing tests . TDD (Test-driven development) It is a kind of automatic test , And give full play to its advantages . If the infrastructure doesn't want to , that TDD It's just the opposite .
Why do you have to write a test first , Is the post test OK ?
That's ok , But after writing the implementation , Write the test now , Use tests to verify the implementation , If the test goes ahead , Use intention driven programming to reduce rework
Test whether the code will become a burden of maintenance ?
Maintenance also follows TDD technological process , First modify the test code to look like the changed requirements , Let the test fail , Then modify the product code to make it pass . So you're not maintaining test cases , It's using test cases .
Why test code should be simple ?
When the test code is simple enough , If a test fails , I have enough confidence to conclude that it must be a product code problem .
When is not suitable for TDD?
If you are doing exploratory technical research (Spike), No need for long-term maintenance , And the cost of testing infrastructure is very high , Let's try it by hand .
And then there is 「 Legacy systems with poor testability 」 and 「 Use test unfriendly technology stacks 」 The system of , do TDD May not be worth it .
reference
《 Background test type definitions 、 Use case specification 》
《 TDD Five steps of development , Take you to practice Test-Driven Development example 》
《 Test-driven development (TDD) Practice and skills 》
《【 Architect's way - O & M and testing 】 piece 5:TDD( Test-driven development ) 》
《 Background automated testing and continuous deployment practice 》
边栏推荐
- FANUC机器人_KAREL编程入门(2)_通用IO信号的使用方法
- Mono 的执行流程
- Code example of hiredis
- 第五章 虚拟存储器 练习
- SqlServer复习
- The Best of Many Worlds_ Dual Mirror Descent for Online Allocation Problems
- 手机办理股票开户安全性高吗?
- What is the difference between WMS warehouse management system and ERP
- oracle设置密码复杂度及设置超时退出的功能
- Is it safe to open a stock account by mobile phone?
猜你喜欢

Basic knowledge diagram of K-line Diagram -- meaning of single K-line

Online sql to htmltable tool
![Leetcode 324 Swing sort II [tri double pointeur] le chemin du leetcode pour l'héroding](/img/41/b8ba8d771b7224eac1cc8c54fe9d29.png)
Leetcode 324 Swing sort II [tri double pointeur] le chemin du leetcode pour l'héroding

keil工程,程序写多后,RTT不能打印

How powerful is the Zadig build? Practice together

Hit the industry directly | the flying propeller launched the industry's first model selection tool

Windows mysql5.7 enable binlog log

一张能卖上千万,商家扩张比玩家还快:球星卡的江湖你不懂

Qtcreater5.15.0 source code compilation process record

One card can sell tens of millions, and the business expansion is faster than that of players: you don't understand the Jianghu of star cards
随机推荐
Zadig + sonarqube, ensuring the safety of the development process
如何结合均线分析伦敦金行情走势线图
Leetcode 324 Swing sort II [tri double pointeur] le chemin du leetcode pour l'héroding
Pytorch builds transformer to realize multivariable and multi step time series forecasting (load forecasting)
非科班!自学之路!
Powerful open source API interface visual management platform Yapi
How powerful is the Zadig build? Practice together
【深度学习】(3) Transformer 中的 Encoder 机制,附Pytorch完整代码
Fanuc robot_ Introduction to Karel programming (2)_ Usage of general IO signal
生产环境sonarqube安装
Is it safe to open a stock account online?
Linux Installation mysql5.7 (centos7.6) tutorial
数学知识:求组合数 I—求组合数
强大的开源API接口可视化管理平台-YApi
Simple understanding of counting and sorting
C语言-单词分析解析
【深度学习】(2) Transformer 网络解析,代码复现,附Pytorch完整代码
Steady! How thousands of micro services can quickly access Zadig (helm chart)
With the development of industrial Internet as the starting point, the industry can enter a new stage of development
2022-06-28:以下golang代码输出什么?A:true;B:false;C:panic;D:编译失败。 package main import “fm