Noise Gate
Noise Gate is the Golang test runner to get faster test results.
Golang is fast and its test is fast as well. However, as you write more tests, the time to run tests gets longer and it's useful if you can select a portion of test functions and run them only.
The popular approaches are something like Run all tests in the current file
and Run a test function at cursor
. Though these approaches are straightforward, they often run unnecessary tests and skip necessary tests.
Noise Gate's approach is Run tests affected by recent edits
. It focuses on the changes since the last test and finds (1)the changed test functions and (2)the test functions which use the changed parts. Then, it runs these functions using go test
. With this approach, it aims to run only the necessary tests and never skip necessary tests.
Prerequisites
Quickstart
You usually use this tool via the editor plugin. So the best quickstart document depends on your editor:
(If your favorite editor is not here, please consider writing the plugin for your editor!)
The document below assumes you use this tool directly, but it's not usual.
--
This quickstart shows you how to use the Noise Gate to get faster test results.
Usually your editor plugin sends the recent edits and the test requests to the server (gated
). In this quickstart, we are going to send them by ourselves using the cli (gate
).
Set up
-
Install the server (gated
) and cli (gate
):
$ go get -u github.com/go-noisegate/noisegate/cmd/gate && go get -u github.com/go-noisegate/noisegate/cmd/gated
-
Run the server (gated
) if it's not running yet.
$ gated
-
Download the quickstart repository.
$ go get -u github.com/go-noisegate/quickstart
Run your tests
Let's assume you just implemented some functions (SlowAdd
and SlowSub
) and tests (TestSlowAdd
, TestSlowAdd_Overflow
and TestSlowSub
) at the quickstart
repository.
-
Run all the tests
First, check if all the tests are passed. Run the gate test
command at the repository root.
$ cd $GOPATH/src/github.com/go-noisegate/quickstart
$ gate test -bypass . -- -v
Run all tests:
=== RUN TestSlowAdd
--- PASS: TestSlowAdd (1.01s)
=== RUN TestSlowAdd_Overflow
--- PASS: TestSlowAdd_Overflow (1.01s)
=== RUN TestSlowSub
--- FAIL: TestSlowSub (1.00s)
math_test.go:22: wrong result: 2
FAIL
FAIL github.com/go-noisegate/quickstart 3.019s
FAIL
- One failed test. We will fix this soon.
- With the
-bypass
option, the tool runs all the tests regardless of the recent changes.
- The
.
arg specifies the directory to run the tests.
- The args after
--
is passed to go test
. -v
is passed in this example.
-
Change the code
To fix the failed test, open the math.go
and change the SlowSub
function. return a + b
at the line 12 should be return a - b
.
-
Hint the change
Run the gate hint
to notify the server of the changed filename and position.
$ gate hint math.go:#176
math.go
is the changed filename and 176
is the byte offset. The offset points to the -
character at the line 12. Usually your editor plugin calculates this offset.
-
Run the tests affected by the recent changes
Let's check if the test is fixed. Run the gate test
again.
$ gate test . -- -v
Changed: [SlowSub]
=== RUN TestSlowSub
--- PASS: TestSlowSub (1.00s)
PASS
ok github.com/go-noisegate/quickstart 1.006s
- Without the
-bypass
option, the tool runs the tests affected by the recent changes.
- The recent changes are listed at the
Changed: [SlowSub]
line. The list is cleared when all the tests are passed.
- Based on the recent changes, the tool selects and runs only the
TestSlowSub
test.
- You get the faster test results (
3.019s
-> 1.006s
)!
How-to guides
Pass options to go test
The args after --
is passed to go test
. For example, the command below passes the build tags.
$ gate test . -- -v -tags tags,list
Run all tests
With the -bypass option, the tool runs all the tests regardless of the recent changes.
$ gate test -bypass . -- -v
How it works
See DEVELOPMENT.md.