hertz
hertz copied to clipboard
optimize: A new optimization for simplifying writing UT file.
What type of PR is this?
Check the PR title.
- [x] This PR title match the format: <type>(optional scope): <description>
- [x] The description of this PR title is user-oriented and clear enough for others to understand.
(Optional) Translate the PR title into Chinese.
简化单测文件编写流程,避免在单测文件中重写handler里出现过的业务逻辑
(Optional) More detail description for this PR(en: English/zh: Chinese).
en:
As shown in the picture from Hertz example, those logic code should already be in the handler file. For the *_test.go UT file, it's not a good practice to copy and pace those code again. Every time we change the handler file, we need to copy again into test file.
Using this PR fix, we can write UT in the way below:
There is no need to copy logic code again now.
zh(optional):
从Hertz的示例代码中可以看到,为了写单元测试代码,需要将接口逻辑在单测函数中重写一遍,但是如果接口逻辑改过了,单测文件中也需要重新复制粘贴一遍,较为麻烦。
通过本PR改动,可以用下面的示例方法来写单测:
不再需要复制粘贴业务逻辑代码。
Which issue(s) this PR fixes:
covered by w := PerformRequest(h.Engine, "GET", "/ping", &Body{bytes.NewBufferString("1"), 1}