gotestdox alternatives and similar packages
Based on the "Go Tools" category.
Alternatively, view gotestdox alternatives based on common mentions on social networks and blogs.
-
JuiceFS
JuiceFS is a distributed POSIX file system built on top of Redis and S3. -
JSON-to-Go
Translates JSON into a Go type in your browser instantly (original) -
kube-prompt
An interactive kubernetes client featuring auto-complete. -
The Go Play Space
Advanced Go Playground frontend written in Go, with syntax highlighting, turtle graphics mode, and more -
Peanut
πΊ Deploy Databases and Services Easily for Development and Testing Pipelines. -
golang-tutorials
Golang Tutorials. Learn Golang from Scratch with simple examples. -
xdg-go
Go implementation of the XDG Base Directory Specification and XDG user directories -
rts
RTS: request to struct. Generates Go structs from JSON server responses. -
typex
[TOOL, CLI] - Filter and examine Go type structures, interfaces and their transitive dependencies and relationships. Export structural types as TypeScript value object or bare type representations. -
golang-ipc
Golang Inter-process communication library for Window, Mac and Linux. -
gothanks
GoThanks automatically stars Go's official repository and your go.mod github dependencies, providing a simple way to say thanks to the maintainers of the modules you use and the contributors of Go itself. -
Viney's go-cache
A flexible multi-layer Go caching library to deal with in-memory and shared cache by adopting Cache-Aside pattern. -
zb
an opinionated repo based tool for linting, testing and building go source -
go-lock
go-lock is a lock library implementing read-write mutex and read-write trylock without starvation -
goroutines
It is an efficient, flexible, and lightweight goroutine pool. It provides an easy way to deal with concurrent tasks with limited resource. -
An exit strategy for go routines.
An exit strategy for go routines -
PDF to Image Converter Using Golang
This project will help you to convert PDF file to IMAGE using golang. -
go-james
James is your butler and helps you to create, build, debug, test and run your Go projects -
import "github/shuLhan/share"
A collection of libraries and tools written in Go; including DNS, email, git ini file format, HTTP, memfs (embedding file into Go), paseto, SMTP, TOTP, WebSocket, XMLRPC, and many more. -
generator-go-lang
A Yeoman generator to get new Go projects started. -
go-sanitize
:bathtub: Golang library of simple to use sanitation functions -
gomodrun
The forgotten go tool that executes and caches binaries included in go.mod files. -
docs
Automatically generate RESTful API documentation for GO projects - aligned with Open API Specification standard -
channelize
A websocket framework to manage outbound streams. Allowing to have multiple channels per connection that includes public and private channels. -
go-whatsonchain
:link: Unofficial golang implementation for the WhatsOnChain API -
Proofable
General purpose proving framework for certifying digital assets to public blockchains -
redispubsub
Redis Streams queue driver for https://godoc.org/gocloud.dev/pubsub package -
ciiigo
[mirror] Go static website generator with asciidoc markup language -
go-slices
Helper functions for the manipulation of slices of all types in Go -
MessageBus implementation for CQRS projects
CQRS Implementation for Golang language -
modver
Compare two versions of a Go module to check the version-number change required (major, minor, or patchlevel), according to semver rules.
Static code analysis for 29 languages.
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of gotestdox or a related project?
README
go install github.com/bitfield/gotestdox/cmd/gotestdox@latest
[Writing gopher logo](img/gotestdox.png)
gotestdox
gotestdox
is a command-line tool for turning Go test names into readable sentences. For example, suppose we have some tests named like this:
TestRelevantIsTrueForTestPassOrFailEvents
TestRelevantIsFalseForNonPassFailEvents
We can transform them into straightforward sentences that express the desired behaviour, by running gotestdox
:
gotestdox
This will run the tests, and print:
β Relevant is true for test pass or fail events (0.00s)
β Relevant is false for non pass fail events (0.00s)
Why
I read a blog post by Dan North, which says:
My first βAha!β moment occurred as I was being shown a deceptively simple utility called
agiledox
, written by my colleague, Chris Stevenson. It takes a JUnit test class and prints out the method names as plain sentences.The word βtestβ is stripped from both the class name and the method names, and the camel-case method name is converted into regular text. Thatβs all it does, but its effect is amazing.
Developers discovered it could do at least some of their documentation for them, so they started to write test methods that were real sentences.\ βDan North, Introducing BDD
How
The original testdox
tool (part of agiledox
) was very simple, as Dan describes: it just turned a camel-case JUnit test name like testFailsForDuplicateCustomers
into a space-separated sentence like fails for duplicate customers
.
And that's what I find neat about it: it's so simple that it hardly seems like it could be of any value, but it is. I've already used the idea to improve a lot of my test names.
There are implementations of testdox
for various languages other than Java: for example, PHP, Python, and .NET. I haven't found one for Go, so here it is.
gotestdox
reads the JSON output generated by the go test -json
command. This is easier than trying to parse Go source code, for example, and also gives us pass/fail information for the tests. It ignores all events except pass/fail events for individual tests (including subtests).
Getting fancy
Some more advanced ways to use gotestdox
:
Exit status
If there are any test failures, gotestdox
will report exit status 1.
Colour
gotestdox
indicates a passing test with a β
(check mark emoji), and a failing test with an x
. These are displayed as green and red respectively, using the color
library, which automagically detects if it's talking to a colour-capable terminal.
If not (for example, when you redirect output to a file), or if the NO_COLOR
environment variable is set to any value, colour output will be disabled.
Test flags and arguments
gotestdox
, with no arguments, will run the command go test -json
and process its output.
Any arguments you supply will be passed on to go test
. For example:
gotestdox -run ParseJSON
will run the command:
go test -json -run ParseJSON
You can supply a list of packages to test, or any other arguments or flags understood by go test
. However, gotestdox
only prints events about tests (ignoring benchmarks and examples). It doesn't report fuzz tests, since they don't tend to have useful names.
Multiple packages
To test all the packages in the current tree, run:
gotestdox ./...
Each package's test results will be prefixed by the fully-qualified name of the package. For example:
github.com/octocat/mymodule/api:
β NewServer returns a correctly configured server (0.00s)
β NewServer errors on invalid config options (0.00s)
github.com/octocat/mymodule/util:
β LeftPad adds the correct number of leading spaces (0.00s)
Multi-word function names
There's an ambiguity about test names involving functions whose names contain more than one word. For example, suppose we're testing a function HandleInput
, and we write a test like this:
TestHandleInputClosesInputAfterReading
Unless we do something, this will be rendered as:
β Handle input closes input after reading
To let us give gotestdox
a hint about this, there's one extra transformation rule: the first underscore marks the end of the function name. So we can name our test like this:
TestHandleInput_ClosesInputAfterReading
and this becomes:
β HandleInput closes input after reading
I think this is an acceptable compromise: the gotestdox
output is much more readable, while the extra underscore in the test name doesn't seriously interfere with its readability.
The intent is not to perfectly render all sensible test names as sentences, in any case, but to do something useful with them, primarily to encourage developers to write test names that are informative descriptions of the unit's behaviour, and thus (as a side effect) read well when formatted by gotestdox
.
In other words, gotestdox
is not the thing. It's the thing that gets us to the thing, the end goal being meaningful test names (I like the term literate test names).
Filtering standard input
If you want to run go test -json
yourself, for example as part of a shell pipeline, and pipe its output into gotestdox
, you can do that too:
go test -json | gotestdox
In this case, any flags or arguments to gotestdox
will be ignored, and it won't run the tests; instead, it will act purely as a text filter. However, just as when it runs the tests itself, it will report exit status 1 if there are any test failures.
As a library
See pkg.go.dev/github.com/bitfield/gotestdox for the full documentation on using gotestdox
as a library package.
So what?
Why should you care, then? What's interesting about gotestdox
, or any testdox
-like tool, I find, is the way its output makes you think about your tests, how you name them, and what they do.
As Dan says in his blog post, turning test names into sentences is a very simple idea, but it has a powerful effect. Test names should be sentences.
Test names should be sentences
I don't know about you, but I've wasted a lot of time and energy over the years trying to choose good names for tests. I didn't really have a way to evaluate whether the name I chose was good or not. Now I do!
In fact, I wrote a whole blog post about it:
It might be interesting to show your gotestdox
output to users, customers, or business folks, and see if it makes sense to them. If so, you're on the right lines. And it's quite likely to generate some interesting conversations (βIs that really what it does? But that's not what we asked for!β)
It seems that I'm not the only one who finds this idea useful. I hear that gotestdox
is already being used in some fairly major Go projects and companies, helping their developers to get more value out of their existing tests, and encouraging them to think in interesting new ways about what tests are really for. How nice!
Some examples
Here is the complete gotestdox
rendering of its own tests (sorted for readability), in case it gives you any useful ideas:
github.com/bitfield/gotestdox:
β EventString formats pass and fail events differently (0.00s)
β ExecGoTest sets OK to false when command errors (0.02s)
β ExecGoTest sets OK to false when tests fail (0.76s)
β ExecGoTest sets OK to true when tests pass (0.63s)
β Filter keeps track of current package (0.00s)
β Filter sets OK to false if any test fails (0.01s)
β Filter sets OK to false on parsing error (0.00s)
β Filter sets OK to true if there are no test failures (0.01s)
β Filter skips irrelevant events (0.01s)
β NewTestDoxer returns testdoxer with standard IO streams (0.00s)
β ParseJSON errors on invalid JSON (0.00s)
β ParseJSON returns valid data for valid JSON (0.00s)
β Prettifier logs to debug writer (0.00s)
β Prettify (0.01s)
β Prettify accepts a single-letter test name (0.00s)
β Prettify accepts a single-word test name (0.00s)
β Prettify does not break words when a digit follows an '=' sign (0.00s)
β Prettify does not erase the final digit in words that end with a digit (0.00s)
β Prettify does not hang when name ends with initialism (0.00s)
β Prettify does not treat an underscore in a subtest name as marking the end of a multiword function name (0.00s)
β Prettify doesn't incorrectly title-case single-letter words (0.00s)
β Prettify eliminates any words containing underscores after splitting (0.00s)
β Prettify handles a test with no name, but with subtests (0.00s)
β Prettify handles multiple underscores, with the first marking the end of a multiword function name (0.00s)
β Prettify inserts a word break before subtest names beginning with a lowercase letter (0.00s)
β Prettify is okay with test names not in the form of a sentence (0.00s)
β Prettify keeps a trailing digit as part of an initialism (0.00s)
β Prettify keeps numbers within a hyphenated word (0.00s)
β Prettify keeps together digits in numbers that are standalone words (0.00s)
β Prettify keeps together hyphenated words with initial capitals (0.00s)
β Prettify knows that just 'test' is a valid test name (0.00s)
β Prettify preserves capitalisation of initialism when it is the first word (0.00s)
β Prettify preserves capitalisation of initialisms such as 'PDF' (0.00s)
β Prettify preserves capitalisation of two-letter initialisms such as 'OK' (0.00s)
β Prettify preserves initialisms containing digits (0.00s)
β Prettify preserves initialisms containing digits with two or more leading alpha characters (0.00s)
β Prettify preserves longer all-caps words (0.00s)
β Prettify recognises a dash followed by a digit as a negative number (0.00s)
β Prettify renders subtest names without the slash, and with underscores replaced by spaces (0.00s)
β Prettify replaces camel-case transitions with spaces (0.00s)
β Prettify retains apostrophised words in their original form (0.00s)
β Prettify retains capitalisation of initialisms in a multiword function name (0.00s)
β Prettify retains hyphenated words in their original form (0.00s)
β Prettify retains quoted words as quoted (0.00s)
β Prettify treats a single underscore as marking the end of a multiword function name (0.00s)
β Prettify treats a single underscore before the first slash as marking the end of a multiword function name (0.00s)
β Prettify treats consecutive underscores as a single word break (0.00s)
β Prettify treats numbers as word separators (0.00s)
β Prettify treats underscores as word breaks (0.00s)
β Relevant is false for non test pass fail events (0.00s)
β Relevant is true for test pass or fail events (0.00s)
Links
Gopher image by MariaLetta
*Note that all licence references and agreements mentioned in the gotestdox README section above
are relevant to that project's source code only.