惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Help Net Security
Help Net Security
www.infosecurity-magazine.com
www.infosecurity-magazine.com
SecWiki News
SecWiki News
Webroot Blog
Webroot Blog
AI
AI
S
Secure Thoughts
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Cloudbric
Cloudbric
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
The Exploit Database - CXSecurity.com
Latest news
Latest news
N
News and Events Feed by Topic
Simon Willison's Weblog
Simon Willison's Weblog
Scott Helme
Scott Helme
S
Schneier on Security
H
Hacker News: Front Page
Forbes - Security
Forbes - Security
T
Troy Hunt's Blog
Know Your Adversary
Know Your Adversary
S
Security Affairs
V
Visual Studio Blog
Stack Overflow Blog
Stack Overflow Blog
博客园_首页
腾讯CDC
GbyAI
GbyAI
有赞技术团队
有赞技术团队
Last Week in AI
Last Week in AI
N
News and Events Feed by Topic
WordPress大学
WordPress大学
The Register - Security
The Register - Security
Engineering at Meta
Engineering at Meta
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cisco Talos Blog
Cisco Talos Blog
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
Recent Announcements
Recent Announcements
V
V2EX
S
Securelist
Security Archives - TechRepublic
Security Archives - TechRepublic
B
Blog RSS Feed
PCI Perspectives
PCI Perspectives
Security Latest
Security Latest
I
InfoQ
I
Intezer
L
LangChain Blog
雷峰网
雷峰网
NISL@THU
NISL@THU
博客园 - 【当耐特】
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志

博客园 - xuld

语言开发笔记3 编译器:类型系统的架构设计 语言开发随笔2 关于产品设计的思考 TS 原理详细解读(6)--语法增量解析 程序员的学习方法 T语言开发笔记1 T 语言语法设计(预审稿) 给萌新的 TS custom transformer plugin 教程——TypeScript 自定义转换器插件 TS 原理详细解读(7)绑定1-符号 TS 原理详细解读(5)语法2-语法解析 T 语言语法设计方案总结 TypeScript 源码详细解读(4)语法1-语法树 TypeScript 源码详细解读(3)词法2-标记解析 TypeScript 源码详细解读(2)词法1-字符处理 TypeScript 源码详细解读(1)总览 7年编程语言设计精华总结——写给想创造或正在创造一门新编程语言的同学 我为什么开发新语言 TypeScript 编译器源码研究(一) gitignore 规范
[讨论]是否将单元测试文件和源文件放在一起
xuld · 2016-10-06 · via 博客园 - xuld

目前根据习惯和创作时间,单元测试和源文件的代码都是分开的。

engine/
  classes/
    Elgg/
      Class.php
  tests/
    phpunit/
      Elgg/
        ClassTest.php

是否可以考虑将它们放在一起:

engine/
  classes/
    Elgg/
      Class.php
      ClassTest.php

好处:

  • 可以很清晰地知道哪些文件缺少测试。
  • 可以快速在源文件和单元测试文件之间跳转,而不需要切换文件夹。
  • 遵循了需要一起修改的代码放在一起的原则,方便修改源码时同步修改单元测试文件。
  • 在移动、拷贝源码时可以轻松地同时处理单元测试代码。

坏处:

  • 将单元测试代码也作为源码处理,有些工具会出现问题,比如有些 IDE 会将单元测试里的代码提示出来。
  • 很少有其它项目这么做。
  • 在搜索源码时必须过滤单元测试的代码。
  • 似乎仅仅为了切换文件方便而增加了其它很多的工作量。
  • 如果单元测试和源码不是一一对应则不容易处理。

结论:

  不要这么做。

参考链接

https://github.com/Elgg/Elgg/issues/7112

http://stackoverflow.com/questions/23990358/keeping-unit-tests-in-separate-files-in-d/24018009