-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support colorized output, indentation in accordance with subtest depth, and one more assertion #1509
Comments
Colorization has been discussed in other issues. See
enhancement: colored output
As for your other three points. Could you please provide examples of output you are seeing and what you would like to see? |
Regarding 1. and 3. assert.True(t, true, "test on the highest level")
t.Run("subtest visualization", func(t *testing.T) {
assert.True(t, false, "deeper level test")
}) Then the expected output would be something like
Regarding 4. tempDir := t.TempDir()
numOfIter := rand.Intn(100)
replacements := map[string]string{
`(?m)^my_dir:\s*\S+$`: "my_dir: " + tempDir,
`(?m)^my_num:\s*\S+$`: "my_num: " + numOfIter,
}
mock.PrepareFileContent("config_template.yaml", "config.yaml", replacements)
// some tests |
regarding indentation, subtests results are already displayed (and indented) in verbose mode. I think what you are really asking is to display assertion results in verbose mode. as subtests work today (unrelated to testify) func TestMain(t *testing.T) {
assert.True(t, true, "true should be true")
t.Run("subtest visualization", func(t *testing.T) {
assert.True(t, true, "true should be true")
t.Run("sub-subtest visualization", func(t *testing.T) {
assert.True(t, true, "true should be true")
})
})
t.Run("subtest visualization3", func(t *testing.T) {
assert.True(t, true, "true should be true")
})
}
now say you modified the func True(t TestingT, value bool, msgAndArgs ...interface{}) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
if !value {
return Fail(t, "Should be true", msgAndArgs...)
}
if tt, ok := t.(*testing.T); ok {
msg := messageFromMsgAndArgs(msgAndArgs...)
tt.Log(msg)
}
return true
} now your output looks like the following
since Go Test doesn't indent the subtest
My current thinking is to let the assertions package do one thing well: check assertions. If passing logs are needed, its easy enough to check the bool returned and use |
The implementation experience gathered by our team showed that the following features currently implemented by our own would improve the overall maintainability of a module to be tested:
Please let me know if these features can be implemented.
Thank you in advance!
The text was updated successfully, but these errors were encountered: