应该将代码更改为与测试套件相对应的更改吗? [英] Should change to code be committed separately from corresonding change to test suite?

查看:94
本文介绍了应该将代码更改为与测试套件相对应的更改吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应该在一次提交中更改代码并相应更改测试套件,还是将其分成两部分?考虑一个错误修复的情况,该错误修复会导致预期输出发生小的变化,从而迫使测试套件发生微小的变化。在同一提交中同时进行两次更改非常方便,因为它使得审阅者明确地知道输出中发生了什么变化。另一方面,有时候您可能只想查看源文件的差异,或差异到预期的输出,如果提交是分开的,则更容易做到这一点。此外,这两件事在逻辑上是不同的,所以做出不同的提交是有意义的。



我希望能够做出两个不同的提交,但不知何故有两个提交以某种方式连接在一起(这样我就可以选择樱桃,还原等等,都可以作为原子单位提交)。
另外,如果创建了两个不同的提交,那么测试套件将在第一次提交时失败(除非引入了第三次提交以放宽测试套件),使未来的二分法变得很痛苦。未来平分失败的问题通常会促使我进行单次提交,但提交应该是逻辑上不同的单元,并且对代码的提交在逻辑上与提交到测试套件中的预期输出不同。



有没有办法让两个不同的提交,而不必向后弯曲,以防止其中之一平分错误? (例如,必须明确提及提交跳过)

解决方案

明确地将这些更改(代码和单元测试) SCM还能够复制给定状态,并且包括程序及其测试。



如果您只需要查看代码更改,仅对 src 执行git diff,而不是 tst 。

因为那些链接的变化仍然存在于一次提交中,您完全避免了对分问题。



总之,保持简单;)

Should a code change and the corresponding change to the test suite be made in one commit, or split into two? Consider the case of a bug fix which causes a small change in the expected output, forcing a minor change in the test suite. It is extremely convenient to have both changes in the same commit, since it makes it obvious to the reviewer exactly what is changed in the output. On the other hand, sometimes you might just want to view the diffs to the source, or the diffs to the expected output and it is much easier to do that if the commits are separate. Also, the two things are logically distinct so it makes sense to make distinct commits.

I would love to be able to make two distinct commits, but somehow have the two commits linked together in some way (so that I can cherry-pick, revert, etc. both commits as an atomic unit). Also, if two distinct commits are made, then the test suite will fail on the first commit (unless a third commit is introduced to relax the test suite), making future bisects a pain. The issue of future bisects failing generally encourages me to make a single commit, but commits should be logically distinct units and a commit to code is logically distinct from a commit to the expected output in the test suite.

Is there a way to make two distinct commits and not have to bend over backwards to prevent bisect from failing on one of them? (eg, having to explicitly mention commits to skip)

解决方案

Definitively keep those changes (code and unit test) as one commit: SCM is also about being able to reproduce a given state, and that include both the program and its tests.

If you need to review only code changes, do a git diff on src only, not on tst.
Since those linked changes remain in one commit, you avoid the bisect issue entirely.

In short, keep it simple ;)

这篇关于应该将代码更改为与测试套件相对应的更改吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆