ittranducloc / btc-indexer

Indexing customized blockchain data from BTC full node

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Write Unit Tests

We have two business components service.Indexer & sync.syncClient that compose of some supported interfaces. The interfaces are defined as subscriber.Subscriber, store.Manager, blockchain.Client. Each interface has an individual functionality that to get more details, please take a look as them.

To be easy to write thoroughly Unit Test for the both important components, we use mixes of some libraries & tools as below:

testify testing suite

Intensively use mock package to mock real objects. Package mock provides a system by which it is possible to mock your objects and verify calls are happening as expected.

You can use the mockery tool to autogenerate the mock code against an interface as well, making using mocks much quicker.

mockery mock generation tool

Installation

go get github.com/vektra/mockery/.../, then $GOPATH/bin/mockery

Most used flags

Name

The -name option takes either the name or matching regular expression of interface to generate mock(s) for.

All

It's common for a big package to have a lot of interfaces, so mockery provides -all. This option will tell mockery to scan all files under the directory named by -dir ("." by default) and generates mocks for any interfaces it finds. This option implies -recursive=true.

Output

mockery always generates files with the package mocks to keep things clean and simple. You can control which mocks directory is used by using -output, which defaults to ./mocks.

ginkgo A Go BDD Testing Framework

gomega Ginkgo's Preferred Matcher Library

  • A matcher/assertion library. It is best paired with the Ginkgo BDD test framework, but can be adapted for use in other contexts too.

About

Indexing customized blockchain data from BTC full node


Languages

Language:Go 98.1%Language:Shell 1.4%Language:Makefile 0.4%Language:Dockerfile 0.1%