agiledragon / gomonkey

gomonkey is a library to make monkey patching in unit tests easy
MIT License
2k stars 179 forks source link

是否考虑支持对单测mock函数的入参进行校验? #79

Closed JiangHanChao closed 2 years ago

JiangHanChao commented 2 years ago

例如:

patches := ApplyFuncSeq(cmdutil.RunCmd, []OutputCell{
        {Values: Params{"123", nil}, ParamCheck: Params{123}},
        {Values: Params{"", ErrTestExcept}, ParamCheck: Params{-1}},
})

cmdutil.RunCmd 函数的多次mock中先检查实际运行时参数是否和期望一致,在很多测试工程中都对参数校验有要求以保证可靠性 不知道gomonkey是否有该方面的想法或者不支持的原因?

agiledragon commented 2 years ago

这个考虑过,想法是在gomonkey既有领域模型之上提供一套完备的DSL,但由于业余时间冲突较多,还没来得及落地。不过以前写过一个demo,你可以看看:https://github.com/agiledragon/gomonkey/blob/master/test/dsl_test/func_dsl_test.go.

欢迎共创!