Skip to Content
学习测试驱动开发
book

学习测试驱动开发

by Saleem Siddiqui
July 2025
Intermediate to advanced
280 pages
3h 5m
Chinese
O'Reilly Media, Inc.
Content preview from 学习测试驱动开发

第 0 章:介绍和设置

干净整洁的代码是成功的关键。

罗恩-杰弗里斯,"清洁代码:学习",2017 年 8 月 23 日,ronjeffries.com

在我们开始进入高要求、高回报的测试驱动开发世界之前,我们需要确保有一个正常工作的开发环境。 本章主要介绍准备和设置工作。

设置开发环境

无论你遵循哪种阅读 途径(见图 P-2),你都需要一个干净的开发环境来学习本书。本书的其余部分假设你已经按照本节所述设置了开发环境。

重要事项

无论您从 Go、JavaScript 还是 Python 中的哪一种开始,都要按照本节所述设置您的开发环境。

常见设置

文件夹结构

创建一个文件夹,作为我们在本书中编写的所有源代码的根目录。 给它取一个几周后你就会清楚明白的名字,例如tdd-project。

在该文件夹下创建以下文件夹:

tdd-project
├── go
├── js
└── py

在编写第一行代码之前,创建所有这些文件夹,即使你打算分多次学习本书,每次学习一种语言。创建这种文件夹结构有以下好处:

  1. 它使三种语言的代码既相互独立,又紧密相连。

  2. 它能确保本书中的大多数命令无需更改即可运行。

    • 处理全限定文件/文件夹名的命令是个例外--这样的命令并不多见。本节就是其中之一。

  3. 它允许在所有三种语言中轻松采用持续集成等高级功能。

  4. 与随附代码库中的文件夹结构相匹配。这有助于在代码发展过程中进行比较和对比。

在本书的其余部分,TDD 项目根目录指的是包含所有源代码的根文件夹,其名称如上:tdd-project 。名为go 、js 和py 的文件夹也使用这些名称--从上下文中可以清楚地看出其含义。

重要

TDD 项目根目录是指包含本书开发的所有源代码的文件夹。它是名为go 、js 和py 的三个文件夹的父文件夹。

声明一个名为TDD_PROJECT_ROOT 的环境变量,并将其值设置为TDD 项目根文件夹的全限定名称。在每个 shell 中都这样做一次(或者在 shell 初始化脚本(如.bashrc 文件)中做一次更好),可确保所有后续命令无缝运行。

export TDD_PROJECT_ROOT=/fully/qualified/path/to/tdd-project

例如,在我的 macOS 系统中,TDD_PROJECT_ROOT 的完整限定路径是/Users/saleemsiddiqui/code/github/saleem/tdd-project 。

文本编辑器或集成开发环境

我们需要一个文本编辑器来编辑源文件。集成开发环境(IDE) 可以提供单一工具,让我们在其中编辑、编译和测试多种语言的代码。不过,这是一个选择和个人偏好的问题;请选择最适合 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

AI原生软件交付

AI原生软件交付

Nick Durkin, Eric Minick, Chinmay Gaikwad
生成式人工智能可视化

生成式人工智能可视化

Priyanka Vergadia, Valliappa Lakshmanan

Publisher Resources

ISBN: 9798341663183