by mrkeen · 2y ago · 0 comments
Maybe you'd lose the:
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
But gain: @ParameterizedTest def 'split #input with sep #sep should return #expected'() {
expect:
Split(input, sep) == expected
where:
testCase | input | sep || expected
"simple" | "a/b/c" | "/" || ['a', 'b', 'c']
"wrong sep" | "a/b/c" | "," || ['a/b/c']
"no sep" | "abc" | "/" || ['abc']
"trailing sep"| "a/b/c/"| "/" || ['a', 'b', 'c']
}Code: https://pastebin.com/14hLe6Fz
And now all of the horribleness of requiring a struct definition + defining the data inside your method + for loop is gone. The intend is clear and based upon your liking you can move the test data into a separate class, at the end of the file or next to the test case.
PS: I just realized you can't edit your post after 1+ hours have passed!
Will do once I’m back from work, ~ 3h