Skip to content

williaminfante/go_test_mocking

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Test Mocking

The accompanying code repo for the Golang Testing: Mocking and Error Handling article.

This repository contains:

  1. maintenance package for the acting third-party dependency package
  2. maintenance_test package for the related tests for the mainatenance package
  3. vehicle package for the target or in-development package
  4. vehicle_test package for the related tests for the vehicle package
  5. main package

Table of Contents

Background

The accompanying code repo for the Golang Testing: Mocking and Error Handling article.

There are two branches used for the demo:

Usage

This requires a minimum version of Go 1.16 and testify 1.7.0.

You can also just execute:

go mod tidy

To run all tests and optionally add -v for verbose, you can just run the following the base repo path:

go test ./... -v

Or go to the folder like the maintenance folder and run

go test -v

To check coverage to the desired output like cover.out in the coverage for all tests, simply:

go test ./... -v -short -coverprofile coverage/cover.out

To create an html-formatted coverage document:

go tool cover -html=coverage/cover.out -o coverage/cover.html

Related Link

Recommended article Golang testing with TDD before reading the accompanying article for this code repo.

Contributing

Please don't hesitate to raise an issue or submit a PR to improve this project. Thanks!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published