All Projects → shihuo-cn → mockit

shihuo-cn / mockit

Licence: MIT license
A tool that integrates SQL, HTTP,interface,Redis mock

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to mockit

instant-mock
Quick and Easy web API mock server.
Stars: ✭ 27 (+107.69%)
Mutual labels:  mock
chip
📦 🐳 🚀 - Smart "dummy" mock for cloud native tests
Stars: ✭ 19 (+46.15%)
Mutual labels:  mock
shai
数据模拟生成库
Stars: ✭ 55 (+323.08%)
Mutual labels:  mock
dexopener
An Android library that provides the ability to mock your final classes on Android devices.
Stars: ✭ 112 (+761.54%)
Mutual labels:  mock
admin-base-tmpl
⚡️基于vite2构建的vue2+typescript+elementUI 的后台基础套件,预览地址
Stars: ✭ 52 (+300%)
Mutual labels:  mock
rocket-pipes
Powerful pipes for TypeScript, that chain Promise and ADT for you 🚌 -> ⛰️ -> 🚠 -> 🏂 -> 🚀
Stars: ✭ 18 (+38.46%)
Mutual labels:  mock
mockingbird
🐦 Decorator Powered TypeScript Library for Creating Mocks
Stars: ✭ 70 (+438.46%)
Mutual labels:  mock
clock
Lendable Clock Abstraction
Stars: ✭ 15 (+15.38%)
Mutual labels:  mock
entity-framework-mock
Easy Mock wrapper for mocking EF6 DbContext and DbSet using Moq or NSubstitute
Stars: ✭ 45 (+246.15%)
Mutual labels:  mock
Mokku
Mock API calls seamlessly
Stars: ✭ 109 (+738.46%)
Mutual labels:  mock
moq.ts
Moq for Typescript
Stars: ✭ 107 (+723.08%)
Mutual labels:  mock
electron-admin-antd-vue
Electron Vue3.x Ant Design Admin template
Stars: ✭ 21 (+61.54%)
Mutual labels:  mock
htest
htest is a http-test package
Stars: ✭ 24 (+84.62%)
Mutual labels:  mock
ts-mock-imports
Intuitive mocking library for Typescript class imports
Stars: ✭ 103 (+692.31%)
Mutual labels:  mock
Paw-FakerDynamicValue
A dynamic value extension for Paw using Faker to generate data
Stars: ✭ 16 (+23.08%)
Mutual labels:  mock
mocat
🐈 Mocat is a mocking toolbar that allows you to interactively develop and test network requests.
Stars: ✭ 27 (+107.69%)
Mutual labels:  mock
axios-mock-server
RESTful mock server using axios.
Stars: ✭ 33 (+153.85%)
Mutual labels:  mock
kugou
multiple implementations for kugou music
Stars: ✭ 25 (+92.31%)
Mutual labels:  mock
joke
Typesafe mock utility with minimal boilerplate for jest
Stars: ✭ 16 (+23.08%)
Mutual labels:  mock
interface-forge
Graceful mock-data and fixtures generation using TypeScript
Stars: ✭ 58 (+346.15%)
Mutual labels:  mock

Mockit

Go Report Card Go

目标:将mock变得简单,让代码维护变得容易

分支介绍

  • main 主分支,覆盖了单元测试
  • light 轻分支,去除了单元测试,简化了依赖项,方便其他团队使用

常见Mock难点

  • 不同中间件,mock库设计模式不一致,学习代价高,差异化明显
  • mock方案强依赖服务端,无法灵活解耦
  • 单元测试适配各种中间件的方案后,依赖管理杂乱
  • 综上所述不想写mock,也没有良好的可执行方案,放弃单测

mockit做到了什么

  • 统一简化语法
  • 无需服务端
  • 解耦依赖项
  • testMain统一管理

mockit 使用

目前支持

  • Redis,MySQL,Interface,HTTP
  • GRPC 可以使用proto生成interface使用Interface模拟
  • ElasticSearch
    • 使用HTTP方式代理client,不过es的返回值比较复杂,请求路径没有普通HTTP直观
    • 使用Interface方式,将dao层抽象成接口方式,这种方式下,接口返回值模拟相对方便直观

理论上业务抽象使用Interface方式都可达成

准备 (具体参照kit_test.go)

  1. interface生成 https://github.com/golang/mock
// interface生成方式
$ mockgen -source ./iface/interface.go -package mockimpl -destination ./mockimpl/interface.go
// 而后将以下new方法的返回值改成interface{}
before: func NewMockDemoInterface(ctrl *gomock.Controller) *MockDemoInterface {
after: func NewMockDemoInterface(ctrl *gomock.Controller) interface{}} {
    mock := &MockDemoInterface{ctrl: ctrl}
    mock.recorder = &MockDemoInterfaceMockRecorder{mock}
    return mock
}
  1. sqlmock依赖replace

目前需要替换下sqlmock库,目前pr还在合并中,预计最近2周就能OK

replace github.com/DATA-DOG/go-sqlmock v1.5.0 => github.com/Rennbon/go-sqlmock v1.5.1-0.20211212104631-9c4a20760689

mockit自身单测

  • 当前目录下 iface 中有4个方法, mockimpl中分别为各个mock实例的实现
  • kit_test.go中mockSrv引用了这些mockimpl实例,在testMain中列举了mock的启动方式,并且在之后所有的Test中介绍了如何使用

引用传送

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].