Ecosyste.ms: Packages

An open API service providing package, version and dependency metadata of many open source software ecosystems and registries.

Top 1.9% on proxy.golang.org
Top 0.3% dependent packages on proxy.golang.org
Top 0.4% dependent repos on proxy.golang.org
Top 4.1% forks on proxy.golang.org
Top 1.8% docker downloads on proxy.golang.org

proxy.golang.org : github.com/gojuno/minimock/v3

Package minimock is a command line tool that parses the input Go source file that contains an interface declaration and generates implementation of this interface that can be used as a mock. 1. It's integrated with the standard Go "testing" package 2. It supports variadic methods and embedded interfaces 3. It's very convenient to use generated mocks in table tests because it implements builder pattern to set up several mocks 4. It provides a useful Wait(time.Duration) helper to test concurrent code 5. It generates helpers to check if the mocked methods have been called and keeps your tests clean and up to date 6. It generates concurrent-safe mock execution counters that you can use in your mocks to implement sophisticated mocks behaviour Let's say we have the following interface declaration in github.com/gojuno/minimock/tests package: Here is how to generate the mock for this interface: The result file ./tests/formatter_mock_test.go will contain the following code: Setting up a mock using direct assignment: Setting up a mock using builder pattern and Return method: Setting up a mock using builder and Set method: Builder pattern is convenient when you have to mock more than one method of an interface. Let's say we have an io.ReadCloser interface which has two methods: Read and Close Then you can set up a mock using just one assignment: You can also use invocation counters in your mocks and tests: minimock.Controller When you have to mock multiple dependencies in your test it's recommended to use minimock.Controller and its Finish or Wait methods. All you have to do is instantiate the Controller and pass it as an argument to the mocks' constructors: Every mock is registered in the controller so by calling mc.Finish() you can verify that all the registered mocks have been called within your test. Sometimes we write tons of mocks for our tests but over time the tested code stops using mocked dependencies, however mocks are still present and being initialized in the test files. So while tested code can shrink, tests are only growing. To prevent this minimock provides Finish() method that verifies that all your mocks have been called at least once during the test run. Testing concurrent code is tough. Fortunately minimock provides you with the helper method that makes testing concurrent code easy. Here is how it works: Minimock comman line args:

Registry - Source - Documentation - JSON
purl: pkg:golang/github.com/gojuno/minimock/v3
License: MIT
Latest release: 5 months ago
First release: almost 5 years ago
Namespace: github.com/gojuno/minimock
Dependent packages: 200
Dependent repositories: 208
Stars: 484 on GitHub
Forks: 31 on GitHub
Docker dependents: 1
Docker downloads: 11
See more repository details: repos.ecosyste.ms
Last synced: 8 days ago

    Loading...
    Readme
    Loading...