← 返回起始笔记位置

知识卡片

普通读书笔记卡 · 8755.a · 生成模型:GPT-6

模拟边界不能掩掉被测责任

理解等级:中级

Mock可隔离外部服务或构造异常,却不应替掉测试想验证的核心训练或转换后只检查类型。需说清本测试哪些是真实执行、哪些是替身,并另用适合层级验证接口集成。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • · 查看原书依据

      mock.patch("train.training_helpers._fit_model", return_value=RandomForestClassifier()) model = train_model() assert isinstance(model, RandomForestClassifier) # good example: behavior-focused test def test_train_model_returns_a_trained_model(): test_data = load_test_data() model = train_model(test_data) valid_predictions = [0, 1, 2] prediction = model.predict(test_data[0]) assert prediction in valid_predictions Notice how the second test was easier to understand? The first test is especially common in cases where the subject under test is poorly written and lacks testable boundaries. A convenient workaround

    参考来源

    - 位置:《Effective Machine Learning Teams (David Tan, Ada Leung, David Colls)》第05章《软件自动化测试》(来源项目:a19c7933-4eda-4176-aebd-30fe7e1ad292;源文件:extracted/Effective Machine Learning Teams (David Tan, Ada Leung, David Colls)/_epub-src/OEBPS/ch05.html) - 结论依据:摘录中关于模拟边界不能掩掉被测责任的定义、比较或条件支撑卡片;原书表述不严谨的范围已在覆盖记录逐项限定,不把案例结果外推为普遍结论。 - 原始内容:mock.patch("train.training_helpers._fit_model", return_value=RandomForestClassifier()) model = train_model() assert isinstance(model, RandomForestClassifier) # good example: behavior-focused test def test_train_model_returns_a_trained_model(): test_data = load_test_data() model = train_model(test_data) valid_predictions = [0, 1, 2] prediction = model.predict(test_data[0]) assert prediction in valid_predictions Notice how the second test was easier to understand? The first test is especially common in cases where the subject under test is poorly written and lacks testable boundaries. A convenient workaround