当前位置:网站首页>TDD开发模式与DDD开发模式
TDD开发模式与DDD开发模式
2022-04-22 04:56:00 【真香号】
TDD 概述
Test-Driver-Development (测试驱动开发) 是敏捷开发中的一项核心实践和技术,也是一种设计方法论。TDD的原理是在开发功能代码之前,先编写单元测试用例代码,测试代码确定需要编写什么产品代码。TDD虽是敏捷方法的核心实践,但不只适用于XP(Extreme Programming),同样可以适用于其他开发方法和过程。
TDD的基本思路就是通过测试来推动整个开发的进行,但测试驱动开发并不只是单纯的测试工作,而是把需求分析,设计,质量控制量化的过程。
TDD的重要目的不仅仅是测试软件,测试工作保证代码质量仅仅是其中一部分,而且是在开发过程中帮助客户和程序员去除模棱两可的需求。TDD首先考虑使用需求(对象、功能、过程、接口等),主要是编写测试用例框架对功能的过程和接口进行设计,而测试框架可以持续进行验证。
所谓测试驱动开发,是指先编写接口,紧接着编写测试。编写完测试后,我们才开始真正编写实现代码。在编写实现代码的过程中,一边写,一边测,什么时候测试全部通过了,那就表示编写的实现完成了:
图示

我们先通过一个示例来看如何编写测试。假定我们编写了一个计算阶乘的类,它只有一个静态方法来计算阶乘:
n!=1×2×3×…×n
代码如下:
public class Factorial {
public static long fact(long n) {
long r = 1;
for (long i = 1; i <= n; i++) {
r = r * i;
}
return r;
}
}
要测试这个方法,一个很自然的想法是编写一个main()方法,然后运行一些测试代码:
public class Test {
public static void main(String[] args) {
if (fact(10) == 3628800) {
System.out.println("pass");
} else {
System.out.println("fail");
}
}
}
这样我们就可以通过运行main()方法来运行测试代码。
不过,使用main()方法测试有很多缺点:
一是只能有一个main()方法,不能把测试代码分离,二是没有打印出测试结果和期望结果,例如, expected: 3628800, but actual: 123456,三是很难编写一组通用的测试代码。
因此,我们需要一种测试框架,帮助我们编写测试。
版权声明
本文为[真香号]所创,转载请带上原文链接,感谢
https://blog.csdn.net/zhanshixiang/article/details/104458161
边栏推荐
- ObjectBox使用记录
- kaggle实战4.1--时间序列预测问题
- cv2. drawContours()、cv2. findContours()、cv2. Usage analysis of boundingrect (IMG) function
- Carina 的根基与诞生背景|深入了解 Carina 系列 第一期
- Chapter 6 Association query
- Garbled code in Web Applications
- vue项目 npm run build 打包项目时为css、js文件加时间戳版本号,防止浏览器缓存
- Common commands of labelme
- Rsync overview
- 2022a special equipment related management (elevator) test question simulation test question bank simulation test platform operation
猜你喜欢

JVM - common parameters
![[chestnut sugar GIS] ArcMap - how to combine multiple images into one](/img/b4/fb1ceaf4cbb040ae0fc1d0ffbc46f9.png)
[chestnut sugar GIS] ArcMap - how to combine multiple images into one

QBoxSet、QBoxPlotSeries

Speech feature extraction of emo-db dataset

2022.04.20 Huawei written examination

Chapter V function
![C language simple [stack and queue] (bracket matching problem)](/img/3d/092daf5d4896aabaf12d34497fe643.png)
C language simple [stack and queue] (bracket matching problem)

Recently, it was found that Baidu cloud sharing should be set with extraction code, and can not be set to sharing without extraction code This article will teach you how to bypass Baidu to set up shar

Pydeck enables efficient visual rendering of millions of data points

C-随手写10
随机推荐
How to initiate mqtt 100 million connection and 10 million message throughput performance test
【Selenium】Yaml数据驱动
Chapter IX user and authority
Data segmentation in training set tuning
cv2. drawContours()、cv2. findContours()、cv2. Usage analysis of boundingrect (IMG) function
Reset kubernetes cluster
Autojs automation script how to develop on the computer, detailed reliable tutorial!!!
kaggle实战4.1--时间序列预测问题
bugly使用记录
Paper reading - access pattern disclosure on searchable encryption: allocation, attack and deviation (2012)
MySQL view character set and proofing rules
Spark starter: wordcount
2021-08-14
Calculator (force buckle)
2019个人收集框架库总结
Pydeck enables efficient visual rendering of millions of data points
Carina's foundation and birth background | deeply understand the first issue of carina series
Spark 入門程序 : WordCount
rpc error: code = Unavailable desc = error reading from server: EOF
Leetcode refers to offer 65 No addition, subtraction, multiplication and division***