How I Learned to Stop Worrying and Like Red Junit Tests
engineering.pivotal.io/post/some-blog-post-or...Posted Apr 10, 2016, 6:06 PM UTC
34
Posted Apr 10, 2016, 6:06 PM UTC
I thought the article made some good points, but in my opinion it doesn't really address its opening line:
Let me throw this scenario at you: A test is failing. You didn’t write it, and the error is really weird. The test name doesn’t tell you what the code is supposed to do, but whatever it is, your code isn’t doing that.
So what do you do when a test written by someone else fails and you don't understand why? And why would you like that situation, other than to try and make a clever article title?
I think their point was to refactor the test to make it easier.
From the title, I was worried that they were going to advocate leaving failing tests failing. Thankfully this was not the case.
This roughly matches my experience writing Java in the industry (specifically, on Google frontends/backends) that can stand both refactoring and 100% automated releases pretty well. Except rather than the ugly underscore thing, the only naming "requirement" in local codebases is that the test name should be a sentence with the verb "should"—so if necessary we can eschew the method name altogether and focus on important end-to-end behaviors.
This is pretty Java-specific, and the article does very heavily get into Java details, but yeah, if you're not using JUnit 4+/Truth/Mockito, start using them.
I'm also a recent convert to using fluent assertion libraries. I started with Hamcrest, but it currently has weird type issues that make it hard to use in some cases, but ended up moving to AssertJ. It makes assertions just a little easier to understand and it provides decent failure messages without you having to write them yourself.