Comments (3)
Colorize output displaying positive results in green and negative ones in red.
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?
from testify.
Regarding 1. and 3.
Assuming the following test located in the function TestIndentation in lines 10 - 13 of the source file /my_path/my_test.go
is executed:
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
=== RUN TestIndentation
...
/my_path/my_test.go:10: <----- in green
test on the highest level <----- in green
=== RUN deeper_level_test
...
/my_path/my_test.go:12: <----- in red
deeper level test <----- in red
Regarding 4.
Assuming the application is using a configuration file config.yaml
containing the name of some necessary directory in the parameter my_dir
and the number of some iterations in the parameter my_num
.
Assuming furthermore that a temporary directory and a random number from 0 to 100 should be used instead in some test cases.
Then tests related to this specific can take the template yaml file called e.g. config_template.yaml
, copy this file to the temporary directory created on the fly and replace the value of my_dir
with the name of this temporary directory and the value of my_num
with a random integer during the copying:
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
from testify.
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")
})
}
go test -v ./...
=== RUN TestMain
=== RUN TestMain/subtest_visualization
=== RUN TestMain/subtest_visualization/sub-subtest_visualization
=== RUN TestMain/subtest_visualization3
--- PASS: TestMain (0.00s)
--- PASS: TestMain/subtest_visualization (0.00s)
--- PASS: TestMain/subtest_visualization/sub-subtest_visualization (0.00s)
--- PASS: TestMain/subtest_visualization3 (0.00s)
PASS
now say you modified the True
assertion method to look something like this.
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
=== RUN TestMain
main_test.go:33: true should be true
=== RUN TestMain/subtest_visualization
main_test.go:35: true should be true
=== RUN TestMain/subtest_visualization/sub-subtest_visualization
main_test.go:37: true should be true
=== RUN TestMain/subtest_visualization3
main_test.go:41: true should be true
--- PASS: TestMain (0.00s)
--- PASS: TestMain/subtest_visualization (0.00s)
--- PASS: TestMain/subtest_visualization/sub-subtest_visualization (0.00s)
--- PASS: TestMain/subtest_visualization3 (0.00s)
PASS
since Go Test doesn't indent the subtest RUN
line, i'm not sure if indenting provides much value
=== RUN TestMain
main_test.go:33: true should be true
=== RUN TestMain/subtest_visualization
main_test.go:35: true should be true
=== RUN TestMain/subtest_visualization/sub-subtest_visualization
main_test.go:37: true should be true
=== RUN TestMain/subtest_visualization3
main_test.go:41: true should be true
--- PASS: TestMain (0.00s)
--- PASS: TestMain/subtest_visualization (0.00s)
--- PASS: TestMain/subtest_visualization/sub-subtest_visualization (0.00s)
--- PASS: TestMain/subtest_visualization3 (0.00s)
PASS
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 T.Log()
from testify.
Related Issues (20)
- Assert: go test output shows subtests that fail as PASS HOT 3
- `YAMLEq` does not validate YAML HOT 1
- Is it possible to assert for multiple allowed values? HOT 2
- Proposal: guard or support comparing with untyped nil HOT 5
- assert/require.Len doesn't print anything if the slice is too long HOT 7
- Allow user to skip (ignore) specific caller frames in assert.CallerInfo() HOT 1
- Unexpected call when interface is parameter HOT 4
- How can I get coverage in the Suite package HOT 6
- Fix CVE-2022-28948 - Remove `gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c` HOT 3
- assert: Equal does not consider Zone information in time.Time
- Update Github actions workflows from nodejs 16 to nodejs 20 before "Spring 2024" HOT 1
- mock: Call.NotBefore still expects calls removed with Call.Unset HOT 6
- unnecessary/incorrect log call in AssertExpectations HOT 2
- Data race when mock is called with refernce to same object as expectation HOT 1
- assert fails and expects to dereference a reference HOT 1
- Add GoLang 1.22 to CI Testing Matrix for Package Compatibility Verification HOT 2
- error while importing github.com/stretchr/testify/suite: read C:\Program Files\Go\src\math\huge_test.go: unexpected NUL in input HOT 1
- AnythingOfType is marked deprecated on pkgsite HOT 1
- .On().Return() doesn't enforce expectation for the returned value HOT 1
- v1.9.0 breaks float comparisons with EqualValues HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from testify.