Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

没有单元测试 #1

Open
rocgao opened this issue Dec 22, 2019 · 3 comments
Open

没有单元测试 #1

rocgao opened this issue Dec 22, 2019 · 3 comments

Comments

@rocgao
Copy link

rocgao commented Dec 22, 2019

我看了一下代码,每个controller里代码都是直接调models.XXX(),例如models.GetMerchantByPhone(userName)。请问用Golang开发的项目是不是基本的单元测试都不用写?controller层的代码直接依赖models.XXX()方法,UT时如何对models.XXX()进行Mock呢?

@kongyuebin1
Copy link
Owner

按照正规的系统开发流程,单元测试是需要的,特别是一些核心的函数模块。很多时候开发,特别不是很庞大的系统,看开发团队的习惯和项目leader的要求。有些是直接用业务来测试,我这个是业余时间写的,没有那么多充足的时间,但是大部分都是经过了业务测试的。

@rocgao
Copy link
Author

rocgao commented Dec 23, 2019

感谢回复!没时间写单元测是可以理解的,但controller层代码直接调用models.XXX()方法,如果以后想写单元测试的话,models.XXX()不方便mock。可以考虑把models.XXX()通过interface来解耦。

@kongyuebin1
Copy link
Owner

好的,谢谢指导

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants