当前位置: 首页 > news >正文

互联网三网合一网站建设二十条优化措施

互联网三网合一网站建设,二十条优化措施,低代码开发平台公司,创建蛋糕网站建设方案GitHub - bytedance/mockey: a simple and easy-to-use golang mock library Go mockito 是什么? mockey是一个简单易用的golang mock库,可以快速方便的mock函数和变量。目前广泛应用于字节跳动服务的单元测试编写。底层是monkey patch,通过在运行时重…

GitHub - bytedance/mockey: a simple and easy-to-use golang mock library

Go mockito 是什么?

 mockey是一个简单易用的golang mock库,可以快速方便的mock函数和变量。目前广泛应用于字节跳动服务的单元测试编写。底层是monkey patch,通过在运行时重写函数指令实现。

  1. 编译时需要关闭inlining和compilation optimization,否则mock可能失败或者报错。有关详细信息,请参阅以下常见问题解答章节。
  2. 在实际编写单元测试的过程中,推荐配合Convey库一起使用。

 

安装

go get github.com/bytedance/mockey@latest

快速指南

import ("fmt""testing". "github.com/bytedance/mockey". "github.com/smartystreets/goconvey/convey"
)func Foo(in string) string {return in
}type A struct{}func (a A) Foo(in string) string { return in }var Bar = 0func TestMockXXX(t *testing.T) {PatchConvey("TestMockXXX", t, func() {Mock(Foo).Return("c").Build()   // mock functionMock(A.Foo).Return("c").Build() // mock methodMockValue(&Bar).To(1)           // mock variableSo(Foo("a"), ShouldEqual, "c")        // assert `Foo` is mockedSo(new(A).Foo("b"), ShouldEqual, "c") // assert `A.Foo` is mockedSo(Bar, ShouldEqual, 1)               // assert `Bar` is mocked})// mock is released automatically outside `PatchConvey`fmt.Println(Foo("a"))        // afmt.Println(new(A).Foo("b")) // bfmt.Println(Bar)             // 0
}

特征

对象

分类

功能细节

函数

基础 mock

普通函数

可变参数函数

普通方法

可变参数方法

嵌套结构体方法

私有类型的导出方法(不同包下)

其他功能

mock 后执行原函数

goroutine 条件过滤

增量改变 mock 行为

获取原函数执行次数

获取 mock 函数执行次数

变量

基础 mock

普通变量

函数变量

 兼容性

OS Support

  • Mac OS(Darwin)
  • Linux
  • Windows

Arch Support

  • AMD64
  • ARM64

Version Support

  • Go 1.13+

License 

 Mockey is distributed under the Apache License, version 2.0. The licenses of third party dependencies of Mockey are explained here.

FAQ 

如何禁用内联和编译优化? 

  1. Command line:go test -gcflags="all=-l -N" -v ./...
  2. Goland:fill -gcflags="all=-l -N" in the Run/Debug Configurations > Go tool arguments dialog box

mock后还是进入了原来的函数?

  1. 尝试使用调试模式。如果能跑通,说明就是问题所在。
  2. 忘记调用了Build(),导致没有实际效果
  3. 目标函数不完全匹配:
    func TestXXX(t *testing.T) {Mock((*A).Foo).Return("c").Build()fmt.Println(A{}.Foo("a")) // enters the original function, because the mock target should be `A.Foo`a := A{}Mock(a.Foo).Return("c").Build()fmt.Println(a.Foo("a")) // enters the original function, because the mock target should be `A.Foo` or extracted from instance `a` using `GetMethod`
    }
  4. 目标函数在其他goroutines中执行:
    func TestXXX(t *testing.T) {PatchConvey("TestXXX", t, func() {Mock(Foo).Return("c").Build()go Foo("a") // the timing of executing 'foo' is uncertain})// when the main goroutine comes here, the relevant mock has been released by 'PatchConvey'. If 'foo' is executed before this, the mock succeeds, otherwise it failsfmt.Println("over")time.Sleep(time.Second)
    }

报错“功能太短无法打补丁”?

  1. 内联或编译优化未禁用:您可以尝试使用调试模式。如果能跑通,说明就是问题所在。请转到常见问题解答的相关部分
  2. 函数真的太短了:意思是目标函数不到一行,导致编译出来的机器码太短。一般两行以上不会出现这个问题
  3. PatchConveyRepeat mocking the same function:以最小单位重复mock同一个函数。如果有这样的需求,请获取Mocker实例并重新mock。
  4. 其他工具mock这个函数:比如monkey或者其他工具mock过这个函数

 

http://www.hrbkazy.com/news/50145.html

相关文章:

  • 福州网站设计网站系统制作最好的网络营销软件
  • 自己做简单网站网络推广外包业务怎么样
  • 网站首页分辨率哪里有营销策划培训班
  • wordpress修改主题header背景色seo优化排名推广
  • 民企品牌建设排名优化哪家好
  • 网站广告用ps如何做海外seo网站推广
  • 网站建站 公司无锡个人推广app的妙招
  • 湛江公司做网站北京百度竞价
  • 网站在香港能备案吗自动点击器下载
  • 网站建设多少钱一年游戏推广员是违法的吗
  • 网站首页标题创建网站的软件
  • 福建seo优化西安seo站内优化
  • 付网站开发费计入什么科目十大网站排行榜
  • 最佳网站西地那非片
  • 家乡政府网站建设评价怎么写公司营销网站建设
  • 温州企业网站开发aso应用优化
  • 免费小程序制作软件搜索引擎优化是指什么意思
  • 拖拽建设网站源码seo咨询师招聘
  • 地方同城网站开发2023年6月份疫情严重吗
  • 苏州园区网站制作公司短视频排名seo
  • 怎么做淘宝网站媒体代发网站
  • 网站开发实用技术第2版西安网络推广seo0515
  • 上海个人做网站南宁网络推广有限公司
  • 卖汽车的网站怎么做开鲁网站seo不用下载
  • 做网站优化的话术弹窗广告最多的网站
  • 博明网站建设近几天发生的新闻大事
  • 任县网站建设设计自己怎么做引流推广
  • 网站制作 电子商城云推广
  • wordpress depthseo技术优化整站
  • 做英语趣味教具的网站个人怎么注册自己的网站