mockery
moq
Our great sponsors
- Onboard AI - Learn any GitHub repo in 59 seconds
- InfluxDB - Collect and Analyze Billions of Data Points in Real Time
- SaaSHub - Software Alternatives and Reviews
mockery | moq | |
---|---|---|
19 | 20 | |
5,259 | 5,487 | |
1.7% | 0.7% | |
9.1 | 0.0 | |
15 days ago | 6 days ago | |
Go | C# | |
BSD 3-clause "New" or "Revised" License | GNU General Public License v3.0 or later |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
mockery
-
go-ecommerce-microservices: A practical e-commerce microservices, built with cqrs, event sourcing, vertical slice architecture, event-driven architecture.
Some of the features: - ✅ Using Vertical Slice Architecture as a high level architecture - ✅ Using Event Driven Architecture on top of RabbitMQ Message Broker with a custom [Event Bus](pkg/messaging/bus/) - ✅ Using Event Sourcing in Audit Based services like [Orders Service](services/orders/) - ✅ Using CQRS Pattern and Mediator Patternon top of Go-MediatR library - ✅ Using Dependency Injection and Inversion of Controlon top of uber-go/fx library - ✅ Using RESTFul api with Echo framework and using swagger with swaggo/swag library - ✅ Using Postgres and EventStoreDB to write databases with fully supports transactions(ACID) - ✅ Using MongoDB and Elastic Search for read databases (NOSQL) - ✅ Using OpenTelemetry for collection Distributed Tracing with using Jaeger and Zipkin - ✅ Using OpenTelemetry for collection Metrics with using Prometheus and Grafana - ✅ Using Unit Test for testing small units with mocking dependent classes and using Mockery for mocking dependencies - ✅ Using End2End Test and Integration Test for testing features with all of their real dependeinces using docker containers (cleanup tests) and testcontainers-go library
-
I want to contribute to open source but don't know where to start
There are some one liner changes you can implement in https://github.com/vektra/mockery
-
Is gomock still maintained and recommended?
When there's just one heavyweight dependency you're interacting with, perhaps a one-off stub/fake is simpler, but I would posit that auto-generated mocks via things like mockery + go:generate leave less test code to maintain vs. perhaps many stubs across the project.
-
How do you write/generate mocks for testing?
My bread and butter is mockery (https://github.com/vektra/mockery). It has a few shortcomings (a config would be really nice in my project) which should be fixed in v3 (https://github.com/vektra/mockery#v3).
-
Layered Architectures in Go
One of the huge benefits to this pattern is testability. Since each layer is injected into each parent layer, we can generate mocks for each layer and inject those instead. For this code we could easily achieve 100% code coverage when unit testing each layer, since we have full control of the child layers. A great tool to use for generating mocks from interfaces is vektra/mokery. One command will create mocks for each of your interfaces that we can inject during test.
-
golang unit testing
I use gomock or mockery for mocking the interfaces and testify for evaluating tests
-
Show HN: Simple Go mocks without interface{}s
Since mockery uses a lot of interface{} magic, adding arguments or return values to interfaces and regenerating the mocks does not get the compiler to complain about existing, now invalid, usages of the mocks. This means that I have to track them down manually. Or, if I'm brave enough, try my hand at a few crazy regexes that never get the job 100% done.
go-mocky does not use interface{}s, and thus can't hide changes to function signatures from the compiler; whenever a mock has been updated and the function signature has changed, the compiler will complain for all existing tests. This means that I can now catch errors at compile/lint time instead of runtime.
Another added benefit is that the go-mocky mocks are dead simple and very easy to write and maintain by hand, should the need ever arise.
-
is there a way to write test in a sane way?
+1 on testify. Started out with that, and it, together with its mocks and the framework mockery are a brilliant combination, assuming you are into testing with mocks to some extent
-
How do you control behaviour in mocked interface ?
I use mockery to generate mocks based on my interfaces: https://github.com/vektra/mockery
-
How do you install commands using go.mod
There are some packages in my project that are not used in the source code, but they're used as commands (i.e. https://github.com/vektra/mockery https://github.com/rubenv/sql-migrate).
moq
-
.NET developers alert: Moq NuGET package exfiltrates user emails from git
Moq’s prior version, 4.18.4, free of the exfiltration behavior, accounts for 6,765,006 downloads in the past six weeks, demonstrating the potential blast radius of privacy breach if a developer hadn’t noticed the issue and raised it with the community.
-
Popular open source project Moq criticized for quietly collecting data
NSubstitute is good, I used it at a previous job.
I've favored Moq in the past because I think there are a couple of things it makes a bit easier or is a bit less opinionated about, but NSub is perfectly cromulent as well.
Someone posted a quick guide to migrating a bunch of it easily in one of the issues in the Moq repo discussing this whole mess: https://github.com/moq/moq/issues/1374#issuecomment-16712411...
-
The Moq-gate: You Either Die a Hero...
Moq was is a popular .NET mocking library that has accumulated over 475.7 million downloads as of now.
-
Since v4.20, Moq is harvesting email addresses
Just don't update to 4.20 until https://github.com/moq/moq/pull/1373 resolved
Maintainer rejected the PR. They have temporarily disabled the integration in https://github.com/moq/moq/pull/1375 but kept the SponsorLink project reference in the source code. It seems like their intent is to re-enable the integration at a later point :(
NSubstitute [0] might be an alternative. Or to fork Moq pre-4.20.
-
Unit & Integration Testing In .Net With Moq and xUnit
Today I want to cover some simple testing setup and configuration. I'll be using my example project from the Dapper & CQRS post I made last week so consider this post a part 2. For tooling I'll be using xUnit and Moq as well as a few other nuget packages to easily configure and run tests in Visual Studio. I am working on a Mac, but operating system shouldn't matter.
-
Cell CMS - Criando testes de maneira prática
Nota: Por muito tempo utilizei uma outra biblioteca chamada Moq que faz a mesma coisa porém com sintaxe diferente. Ultimamente tenho dado preferência pelo NSubstitute exatamente por parecer legível.
What are some alternatives?
gomock - GoMock is a mocking framework for the Go programming language.
counterfeiter - A tool for generating self-contained, type-safe test doubles in go
minimock - Powerful mock generation tool for Go programming language
go-sqlmock - Sql mock driver for golang to test database interactions
moq - Interface mocking tool for go generate
hoverfly - Lightweight service virtualization/ API simulation / API mocking tool for developers and testers
gock - HTTP traffic mocking and testing made easy in Go ༼ʘ̚ل͜ʘ̚༽
webmock - Webmock for Golang, to stub requests.
mockcompose - mockcompose generates mocking implementation for Go classes, interfaces and functions
mockitout - A language agnostic HTTP mock server for quick stub testing
go-smtp-mock - SMTP mock server written on Golang. Mimic any 📤 SMTP server behavior for your test environment with fake SMTP server.
Mmock - Mmock is an HTTP mocking application for testing and fast prototyping