测试驱动开发(TDD)与快速可靠测试指南
1. 示例代码与TDD基础
在开发中,我们会遇到各种测试场景。例如有这样的测试用例:
it("fails fast when no parameter provided", ...);
it("fails fast when wrong parameter type provided", ...);
最终的生产代码如下:
export function transform(input) {
if (input === undefined || typeof input !== "string") {
throw new Error("Expected string parameter");
}
let result = "";
for (let i = 0; i < input.length; i++) {
let charCode = input.charCodeAt(i);
result += transformLetter(charCode);
}
return result;
}
function transformLetter(charCode) {
if (isBetween(charCode, "a", "m") || isBetween(charCode, "A", "M")) {
charCode += 13;
} else if (isBetween(charCode, "n",
超级会员免费看
订阅专栏 解锁全文
与快速可靠测试指南&spm=1001.2101.3001.5002&articleId=150845868&d=1&t=3&u=816d6d8fc79e4339aab7b3ec031f6d0b)
1088

被折叠的 条评论
为什么被折叠?



