
Engineering test improvements (internal tooling)
Another internal tools example from improving engineering testing coverage.
Transcript
This transcript is auto-generated. Names and product terms may be wrong.
Right. I have another demo. This is also sort of an internal um focused one, but it's nothing really specific to us. So um this is about some of our tooling and kind of a PSA for the backend developers. So if you're ever running tests, I've just got this my demo test here and you see some failures that are like expected true but was false.
Expected true was is false. it doesn't really tell you much. Or these ones where it's like expected this really long string, but it was actually this other really long string and I don't really know what's going on. I got to squint at it all. So that's because we're using JUnit, which is the pretty much standard Java testing unit, but I've recently added support for Truth, which is another testing framework from Google.
So I can rewrite some of these to say import. I'll destroy my import. And then I can change my assert equals down here to be assert that actual is equal to expected. Replace that. And then I've got like this. Here's in one of these. Let's see. Yeah. Yeah. assert true list contains element. I can change that to assert.list contains element.
All right. If I save those and I rerun my test. Oops, wrong window there my search and demo. Now, I'm gonna find that it's actually trimmed out most of the text and just highlights the part that has the change in it. So, it's a lot easier to find that. And then also the I did the one that says the list contains the element and now it says was expected to contain grapes that actually contained all this other parts.
So, that's cool, but it's kind of a pain to go rewrite all of these. Um, so I went ahead and I looked into this tool called Smp. And if I go sp and I run this JUnit truth um, YAML that I set of rules that I made, it will actually go and take that file and do some pattern matching and change my assert equals to assert that this is equal to that.
This assert true change to asserting that something is true. That's pretty good. But I still have just an asserting it's true at the end. Um, so I wrote another set of some GP rules which will actually take those and switch around and find that if we have asserting a size is equal to something, we actually say assert the list has size.
Or if we're doing an assertion on containing a key, we can use native assertions. Now when we run our tests all of those have you know better outputs and so I have I can say that my map has a particular key and it includes all the other parts. Um I can say that the collection was meant to be empty and it told me what was in it.
Um there's a whole bunch of other rules. I made some uh I got Claude to help me make a giant list of all the different patterns. Um, so I'll hopefully slowly be switching over a lot of our assertions in this in the codebase to help make it easier for people to read when they have test failures. And I encourage people to start using it themselves.
Um, hit me up if you have any questions. There's lots of good docs out there, too.