Skip to content
Example showing how to test exec.Command in Go
Go
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
funshell
LICENSE
README.md
go.mod
go.sum
main.go

README.md

Example repo of how to test exec.Command (and other system functions) in Golang

Accompanies this article: Unit-Testing-Exec-Command-In-Golang

Overview

Package funshell contains the ShellCommand function which is being tested.
ShellCommand just kicks off the shell command echo 'fun!'.
The main function in main.go just calls this, catches errors and then prints out anything that was output to stdout.
Package funshell_test runs some simple unit tests against ShellCommand.

Running

Run the program with go run main.go.
Run the tests with go test ./...

You can’t perform that action at this time.