hertz icon indicating copy to clipboard operation
hertz copied to clipboard

optimize: A new optimization for simplifying writing UT file.

Open learningpro opened this issue 3 years ago • 1 comments

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: image 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: image There is no need to copy logic code again now.

zh(optional): image 从Hertz的示例代码中可以看到,为了写单元测试代码,需要将接口逻辑在单测函数中重写一遍,但是如果接口逻辑改过了,单测文件中也需要重新复制粘贴一遍,较为麻烦。 通过本PR改动,可以用下面的示例方法来写单测: image 不再需要复制粘贴业务逻辑代码。

Which issue(s) this PR fixes:

learningpro avatar Oct 28 '22 08:10 learningpro

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Oct 28 '22 08:10 CLAassistant

covered by w := PerformRequest(h.Engine, "GET", "/ping", &Body{bytes.NewBufferString("1"), 1}

welkeyever avatar Oct 31 '22 11:10 welkeyever