gf icon indicating copy to clipboard operation
gf copied to clipboard

fix: use upper camel case to unify the case name of unit testing cases

Open oldme-git opened this issue 1 year ago • 9 comments

Dear reviewer: 统一单元测试的函数命名为大写驼峰,向 golang 标准库对齐 加入 ci 检测,不符合要求的抛出 fail,请详细 review .github/workflows/before_script.sh

库里有些单测不是很严谨,同一个包里甚至有 Test_Abc_Def, TestAbcDefTest_abc_def

oldme-git avatar Mar 19 '24 15:03 oldme-git

@oldme-git 我看改动的文件比较多,都是把下划线改为了大驼峰,但在单测命名这块本身没有规范,这么大量的修改看不出来能给项目带来什么收益。

gqcn avatar Mar 21 '24 14:03 gqcn

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@oldme-git I see that there are many files that have been changed, and the underscores have been changed to hump. However, there is no standard in the naming of single tests. It is hard to see what benefits such a large number of changes can bring to the project.

Issues-translate-bot avatar Mar 21 '24 14:03 Issues-translate-bot

@oldme-git 我看改动的文件比较多,都是把下划线改为了大驼峰,但在单测命名这块本身没有规范,这么大量的修改看不出来能给项目带来什么收益。

单测命名这块的规范官方给的示例都是 TestXxx,第三方规范也都是 TestXxx,哪怕不批量改成TestXxx,也要统一一种风格比较好吧,你看呢

oldme-git avatar Mar 22 '24 01:03 oldme-git

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@oldme-git I see that there are many files that have been changed, and the underscores have been changed to hump. However, there is no standard in naming single tests. It is hard to see what benefits such a large number of changes can bring to the project.

The official examples of single test naming specifications are all TestXxx, and the third-party specifications are also TestXxx. Even if you don’t change them to TestXxx in batches, it’s better to unify one style. You see?

Issues-translate-bot avatar Mar 22 '24 01:03 Issues-translate-bot

@oldme-git 我重新回顾了一下,这里的下划线最初是参考标准库的example代码,如果是函数的example那么是不带下划线的,但如果是结构体的单测,那么是需要通过下划线来分隔开的。并且godocgoland也是按照这个规则进行代码提示识别,具体可以看下文档:https://goframe.org/pages/viewpage.action?pageId=1114321 图片

gqcn avatar Mar 25 '24 14:03 gqcn

@gqcn 我详细看了一下 go 标准库,Example 确实会使用下划线,但是单测 Test 没有使用下划线的案例,另外,其他的开源项目,如 opentelemetry-go, gin,都是使用的 TestXxx,当前 gf 两种方式混用,项目大了还是注意一下规范比较好,对齐开源社区的规范也不会带来什么风险

oldme-git avatar Mar 27 '24 07:03 oldme-git

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@gqcn I looked at the go standard library in detail. Example does use underscores, but there is no case of using underscores in single test Test. In addition, other open source projects, such as opentelemetry-go, gin, all use underscores. TestXxx, currently the two methods of gf are mixed. If the project is large, it is better to pay attention to the specifications. Aligning with other open source projects will not bring any significant risks.

Issues-translate-bot avatar Mar 27 '24 07:03 Issues-translate-bot

@gqcn 另外,虽然没有正式的 go 官方标准,但是在开发文档中还是提及了 Test 的命名标准。参见: https://pkg.go.dev/testing#section-documentation

oldme-git avatar Mar 27 '24 07:03 oldme-git

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@gqcn In addition, although there is no formal go official standard, the naming standard of Test is still mentioned in the development documentation. See: https://pkg.go.dev/testing#section-documentation

Issues-translate-bot avatar Mar 27 '24 07:03 Issues-translate-bot

Close due to in activity for long time.

gqcn avatar Sep 13 '24 02:09 gqcn