Testing Icon

Testing

Testing is the practice of systematically checking if code functions as intended.
7 Stories
All Topics

Yegor Bugayenko www.yegor256.com

How I test my Java classes for thread-safety

Yegor Bugayenko: Thread-safety is an important quality of classes in languages/platforms like Java, where we frequently share objects between threads. The issues caused by lack of thread-safety are very difficult to debug, since they are sporadic and almost impossible to reproduce on purpose. How do you test your objects to make sure they are thread-safe? Here is how I'm doing it. Great details on a particularly difficult aspect of testing. ✨

read more...

Mihai A www.amihaiemil.com

Test Driven Rest

Mihai A: If we agree that a RESTful API should offer more or less the same functionality as the UI, then we can use the same tests for UI automation and for API testing, provided that we make the right abstractions and link them together properly -- this will guarantee that the API is navigable and respects the HATEOAS principle. HATEOAS, for those wondering, stands for Hypermedia As The Engine Of Application State, which is a fancy way of saying the REST application exposes its state (where resources are and how you can interact with them) via hypermedia embedded in API responses. The advantage of this is: A REST client needs no prior knowledge about how to interact with an application or server beyond a generic understanding of hypermedia. In practice, HATEOAS is often left off (which pretty much defeats the purpose of REST, but c'est la vie). The result is a "RESTful" API. Meaning it's like REST but it ain't really REST. I like well-designed RESTful APIs because they are easy to navigate logically, but true REST APIs don't need to be navigated at all, which is way cooler. But I digress, back to Mihai and this excellent post on testing: The code that tests the UI should also test the API. It is achievable, provided that the architect pays as much attention on the tests as he does on the app’s code (which, sadly, is not always the case). He goes on to show example code testing the GitHub API. Good stuff 👌

read more...

Node.js Icon meowni.ca

Automatic visual diffing with Puppeteer

Monica Dinculescu: I did a little song-and-dance that sets up Puppeteer , takes screenshots of your app (like, all the routes you care about), and then compares them to the “golden” ones. If they match, your test passes! It only works with Chrome (because Puppeteer), but that's not a big deal since this is the kind of thing you only put in your devDependencies. The results are super cool in your test suite output:

read more...

Elixir Icon spin.atomicobject.com

Behaviour-Driven Unit Testing for Phoenix Controllers

This is a great introduction to the Mox library written by José Valim and the Plataformatec team. Mox' philosophy: A simple summary is that when it comes to dependency injection, mocks should not be created ad-hoc. Instead, they should be constrained by predefined behaviours. This helps enforce contracts between modules, and it also makes tests easier to maintain and understand. We've been using the Mock library when testing against 3rd party services, and it works as advertised. However, we don't test our controllers in isolation like in this post. Should we be?

read more...
0:00 / 0:00