Test Suite HTML Reporter
A simple Reporter implementation that generates HTML reports for BDD test suites written using goblin.
Options
The reporter supports the following options specified as command line arguments:
report.file
- The primarily report output file. This file contains the full aggregated results of all tests that were executed. Default value if not specified is$PWD/test-results/index.html
report.preserve
- A flag used to indicate that report output should be preserved. If this flag is specified, a directory hierarchy will be created per test run under which all report files will be generated. The top level directory will still be the parent directory of the report file specified (or default location). Under this parent directory, two additional levels of directories will be created:day
- A directory with the current day in ISO 8601 format -yyyy-MM-dd
time
- Created under theday
directory with current time -hhmmss
Output Files
The reporter produces the following output files:
<directory>/index.html
- A simple index file that just lists the individual test results files, and the summary and results files.<directory>/summary.html
- Test result summary in tabular format.<directory>/results.html
- The full aggregated results of the test suite. This is the file that is specified as command line argument to control the output directory if the default is not desired.<directory>/<TestName>.html
- Report with results from executing the test.
Running
The following simple suite shows how to setup and use the html reporter. It just requires two additional lines of code in the test file (comments Line 1 and Line 2). The rest is standard goblin BDD test suite.
You can specify the main output file (default $PWD/test-results/index.html
) by specifying a flag.
go test -report.file=/tmp/test.html
or to specify the target output directory and desired report file name as well as to preserve all report files per run
go test -report.file=/tmp/test.html -report.preserve
or to preserve all report files per run, but use the default output directory
go test -report.preserve
Consolidated test output will be written to the specified (or default) html file. In addition, the reporter creates a Test<Xxx>.html
for each test (TestXxx
) under the parent directory (default $PWD/test-results
) as well as a summary.html
file.
Sample Test
package main import ( "testing" "github.com/franela/goblin" ) func TestAuth(t *testing.T) { g := goblin.Goblin(t) GetReporter().RegisterTest(t.Name()) // Line 1 g.SetReporter(goblin.Reporter(GetReporter())) // Line 2 var Describe = g.Describe var It = g.It var Assert = g.Assert Describe("Login and logout from API", func() { var token string It("Login with username/password credentials", func() { response, tk, errs := login() Assert(errs == nil).IsTrue("Endpoint returned errors") Assert(response.StatusCode).Equal(200) Assert(len(tk) > 0).IsTrue("Endpoint did not return token") token = tk }) It("Logout the JWT Token", func() { response, errs := logout(token) Assert(errs == nil).IsTrue("Endpoint returned errors") Assert(response.StatusCode).Equal(200) }) It("Cannot use API with deleted token", func() { response, _, errs := customerByCode(token, "test") Assert(errs == nil).IsTrue("Endpoint returned errors") Assert(response.StatusCode).Equal(403) }) It("Cannot logout invalidated JWT Token", func() { response, errs := logout(token) Assert(errs == nil).IsTrue("Endpoint returned errors") Assert(response.StatusCode != 200).IsTrue("Unexpected response code when logging out invalidated token") }) }) }
Sample summary report
Test Suite | Tests Passed | Tests Pending | Tests Failed | Total Time |
---|---|---|---|---|
TestSensor | 15 | 0 | 0 | 49 (ms) |
TestFacility | 18 | 0 | 0 | 65 (ms) |
TestReelRetrieval | 12 | 0 | 0 | 188 (ms) |
TestAuth | 4 | 0 | 0 | 72 (ms) |
TestCustomer | 28 | 0 | 0 | 87 (ms) |
TestGateway | 15 | 0 | 0 | 43 (ms) |
TestUserUpdate | 29 | 0 | 0 | 759 (ms) |
TestUser | 10 | 0 | 0 | 572 (ms) |
TestCustomerRetrieval | 12 | 0 | 0 | 319 (ms) |
TestFacilityRetrieval | 12 | 0 | 0 | 197 (ms) |
TestCable | 14 | 0 | 0 | 47 (ms) |
TestGatewayRetrieval | 12 | 0 | 0 | 223 (ms) |
TestManufacturer | 11 | 0 | 0 | 34 (ms) |
TestReel | 15 | 0 | 0 | 49 (ms) |
TestSensorRetrieval | 13 | 0 | 0 | 243 (ms) |
TestUserRetrieval | 22 | 0 | 0 | 501 (ms) |
TestApiKey | 11 | 0 | 0 | 30 (ms) |
TestCableRetrieval | 12 | 0 | 0 | 181 (ms) |
Total | 265 | 0 | 0 | 3668 (ms) |
Sample individual test report
$PWD/test-results/TestAuth.html
TestAuth
Login and logout from API- ✓ Login with username/password credentials (61 ms)
- ✓ Logout the JWT Token (3 ms)
- ✓ Cannot use API with deleted token (3 ms)
- ✓ Cannot logout invalidated JWT Token (2 ms)