首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在恢复提交和保存单元测试时检查测试?

如何在恢复提交和保存单元测试时检查测试?
EN

Stack Overflow用户
提问于 2016-02-19 14:30:46
回答 1查看 68关注 0票数 0

我正在处理一个开源项目。事实上,我有一个大师的克隆,我正在编写单元测试。现在,在编写单元测试(例如在abc.cxx中)之后,我想通过恢复commit来检查我的测试是否失败(我有修复错误的修补程序的提交ID )。

那么,通过git命令检查这个问题的最佳方法是什么。我已经尝试过git还原,但是我的测试也被擦除了(在abc.cxx中),并且我无法测试这个函数。

我是一个git的初学者,任何类型的错误都可能导致我的大师的重建(6-7小时)。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-19 15:10:48

我建议:

  1. 在一个专用的临时分支中提交单元测试,
  2. 恢复这个分支中的错误修复,
  3. 测试你的单元测试,
  4. 如果一切正常,请在主服务器上重新设置/合并单元测试。

演示:

代码语言:javascript
运行
复制
# INIT
$ git init test
Initialized empty Git repository in /tmp/test/.git/
$ cd test/
$ echo bug > file
$ git add file
$ git commit -m"Commit with bugs in it"
[master (root-commit) 498680f] Commit with bugs in it
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 file
$ echo feature > file
$ git commit -am"Fix bug #1"
[master 05540d3] Fix bug #1
 1 files changed, 1 insertions(+), 1 deletions(-)

# (1)
$ echo 42 > unit-test
$ git add unit-test
$ git checkout -b unit-test
A   unit-test
Switched to a new branch 'unit-test'
$ git commit -m"Add unit test for bug #1"
[unit-test 240bc6c] Add unit test for bug #1
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 unit-test
$ git l
* 240bc6c (HEAD, unit-test) Add unit test for bug #1
* 05540d3 (master) Fix bug #1
* 498680f Commit with bugs in it

# (2)
$ git revert 05540d3
Finished one revert.
[unit-test 5f5eb62] Revert "Fix bug #1"
 1 files changed, 1 insertions(+), 1 deletions(-)
$ git l
* 5f5eb62 (HEAD, unit-test) Revert "Fix bug #1"
* 240bc6c Add unit test for bug #1
* 05540d3 (master) Fix bug #1
* 498680f Commit with bugs in it

# (3)
$ # check for bug

# (4)
$ git checkout master
Switched to branch 'master'
$ git rebase 240bc6c
First, rewinding head to replay your work on top of it...
Fast-forwarded master to 240bc6c.
$ git branch -D unit-test
Deleted branch unit-test (was 5f5eb62).
$ git l
* 240bc6c (HEAD, master) Add unit test for bug #1
* 05540d3 Fix bug #1
* 498680f Commit with bugs in it
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35507700

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档