Improving Readability of Test Results
Developers in the Golang community execute unit tests using 'go test'. As the number of tests grows, it becomes increasingly challenging to locate information about test cases that have failed within the results of unit tests.
The tool called rakyll/gotest has addressed this issue by adding color to the output of 'go test'.
However, as an alternative solution to this problem, I have created the spectest command that "extracts information about failed unit tests" and outputs statistical information about the tests.
I write down the same content as in the GIF image below.
$ spectest ./...
....................................................................................................................................................................................................................................................................................................................................................................................................
[Error Messages]
--- FAIL: Test_goldenFile_write (0.00s)
--- FAIL: Test_goldenFile_write/should_write_data_to_the_golden_file (0.00s)
file_system_test.go:51: write() file does not exist
--- FAIL: TestIntervalDuration (0.00s)
--- FAIL: TestIntervalDuration/get_1[ns]_duration (0.00s)
time_test.go:55: duration should be 1 second, but 8760h0m0.000000001s
[Test Results]
- Execution Time: 4.918126564s
- Total : 388
- Passed : 384
- Failed : 4
- Skipped : 0
How It Works
spectest can be used with the same options as 'go test'. This is because spectest directly passes the command-line arguments it receives to 'go test'.
spectest reads the output (stdout) of 'go test' in real-time. If a test is successful, it displays a green dot; if it fails, it shows a red dot. After all tests are completed, it searches the results of 'go test' for the "failed test method name" and the "reason for failure" if there are any failed test cases.
(In the parsing process, I'm writing some clumsy code :) Perhaps, a month later, it might be hard to understand.)
Promotion
The go-spectest/spectest project provides commands and libraries related to testing. While the library is specialized for API testing, the commands are designed to be usable by all Golang users (meaning you don't need to use the spectest library).
Ref. spectest - API testing library for Go that generate E2E test result document in markdown
Ref. spectest roadmap
I have a keen interest in testing and aim to create an environment that makes testing easy for developers. Even if the entire project doesn't persist, I continue to develop some of the open-source software (OSS) I've created, hoping it remains useful to everyone.
If you support my efforts, receiving GitHub Stars would be encouraging. I would be delighted if you use spectest and provide feedback.
Top comments (0)