by alkonaut · 1y ago · 0 comments
The lesser evil is to just ”do what you need and test everything once you are arranged”.
You won’t get hundreds of neatly separated well-named test cases which fail for a single reason. But for slow tests that isn’t as important as keeping the redundant setup away.
I like the tree idea but once we have simple pure/immutable we don’t really have the problem of redundant setup being slow, just ugly.
Setup: login. Test 1: delete your account. Test 2: can change username.
The last time I saw this handled was a test copy of db per thread and transactional test rolled back. Not great but it did 10x our pipelines and avoided locks and issues.
BUT obviously you can just test deleting the account at the end of the test that modifies the account.
SetAccountUserName(account, "New name"); GetAccount(account.id).UserName.Should().Be("New name");
SetAccountEmail(account, "new@email"); GetAccount(account.id).Email.Should().Be("new@email");
DeleteAccount(account); GetAccount(account.id).Should().BeNull();
This is a working timeline
But they commit an entirely new test filled with redundant stuff that takes way longer than is necessary and makes it unclear which assertion was the critical one. Because hey, look at all that green text in my PR. I'm so thorough.