by ash on 12/6/23, 12:58 AM with 47 comments
by tylerneylon on 12/6/23, 2:25 AM
This is the complete txtar file format: One or more comment lines followed by zero or more virtual files. Each virtual file begins with a line like “-- filename --“ and ends at the next such line. Specifically, these filename lines are those beginning with dash dash space and ending with space dash dash. That’s the whole format.
It avoids the need to have multiple real files all over the place when you want just one real file but you want your code to think in terms of multiple files. (Eg have one txtar file that combines different blocks of test data.)
by peter_l_downs on 12/6/23, 1:53 AM
shameless advert: do you wish testify was implemented with generics and go-cmp, and had a more understandable surface area? Check out my small library, testy https://github.com/peterldowns/testy
shameless advert: do you want to write tests against your postgres database, but each new test adds seconds to your test suite? Check out pgtestdb, the marginal cost of each test is measured in tens of milliseconds, and each test gets a unique and isolated postgres instance — with all your migrations applied. https://github.com/peterldowns/pgtestdb
by mcint on 12/6/23, 1:47 AM
by devjam on 12/6/23, 2:50 AM
If you use VSCode with the Go extension it's already available there as a command "Go: Generate Unit Tests for Function/Package".
by jeffrallen on 12/6/23, 6:52 AM
This, in the same organization where another team was told by it's VP, "don't schedule time for unit tests, we are too far behind schedule for a luxury like that".
All this to say, #3 "coverage is not a substitute for thinking" really hit me in the (grumpy) feels.
by ijustlovemath on 12/6/23, 1:35 AM
It also really helps you to properly model your problem by breaking things out into their simplest possible components, and makes porting to a new implementation a breeze; reproduce a quick test data parser and some simple case logic, and you're well on your way to having two totally matching, but also totally separate, implementations!
...all of this without reinventing Lisp, of course ;)
by tptacek on 12/6/23, 5:37 AM
by imran-iq on 12/6/23, 2:08 AM
---
by dharmab on 12/6/23, 1:50 AM
"Learn Go with Tests" book: https://quii.gitbook.io/learn-go-with-tests
"Go by Example": https://gobyexample.com/
by manlobster on 12/6/23, 4:25 AM
It would make me uncomfortable to rely on tests like some of the examples in this talk, that have such a degree of complexity without explicit tests. Code such as to parse a text file should be in its own package. The package should expose an extremely readable API, and it should have its own suite of tests.
Similarly, writing formatting code for error messages and diffs inline makes the tests less readable and therefore less reliable. The golang standard library should include testing helpers such as in `testify`, which would allow tests to be concise, less buggy, and extremely readable.
by ithkuil on 12/6/23, 9:40 AM
But perhaps I don't know how to do it. In most of the rust codebases I worked with tests contain sequences of asserts (the failure of which causes the whole test to fail). Procedural macros are often employed to create many smaller tests that seem to address the use case of table driven tests + t.Error or subtests.
Macros in rust are ... adequate, but there is something bout being able to just express your logic in your main language instead of having to fiddle with a macro language and effectively code generation.
Does anybody have good tips for bringing some of the enjoyable testing patterns from Go into Rust?
by ilrwbwrkhv on 12/6/23, 2:14 AM
by hknmtt on 12/6/23, 8:31 AM
Although I have yet to make integration tests that require live database and other dependencies. That will be fun...
Anyway, my main gripe with tests or TDD is that even if the code base is 95% finished, not talking libraries here, even small code changes can cause a cascade of changes that need to be addressed and tests essentially multiply the work load by a factor of 10, easy. And I am not talking about big changes. It might be a simple addition of a new struct field which suddenly breaks half of your test suite. Hence teste should be, in my experience, written as the absolutely last step before going live. Otherwise they might impose massive costs on time, and potentially money(if we're talking actual business and not one man shot type of project).
by GamerAlias on 12/6/23, 1:44 AM
by earthboundkid on 12/6/23, 3:19 AM
by jimmyed on 12/6/23, 3:15 AM