Below you will find pages that utilize the taxonomy term “Testing”
Posts
How to Randomize Tests in JUnit with Gradle and JUL
The ability to randomize the order of tests has always been a useful tool for diagnosing flaky tests. However, until JUnit 5.8.0, developers were only able to randomize the order of methods within a test class using MethodOrder$Random. With the addition of MethodOrderer$ClassOrderer, it is now possible to randomize the test classes too.
For the rest of this article, I will walk you through how to enable test classes and methods to run in a random order with the following steps:
read more
Posts
Mocking Functions in Elixir With ExDoubles
So I would have considered this crazy a few years ago, but I wrote my own mock framework in Elixir called ExDoubles.
I know, I know, there are tons of them already, but hear me out. This one seeks to act like mock libraries in other languages, and put focus on the key element of abstraction in Elixir, the function.
Why? Why? Why? I have been working in Elixir for the last six months, after years of Ruby and C#.
read more
Posts
How to Test Private Methods in Ruby and Rails?
So you have written an implementation for that new feature in your Rails app, but your team won’t accept your Pull Request until there are unit tests. What’s more your changes are to private methods of a class. In frustration, you shout, “How do I unit test this code?”
The key to unit testing private methods, in any language, is to test them through the public ones.
Through almost two decades of practicing test-driven development, and writing unit tests in many languages at several large companies, including GitHub and Pivotal Labs, I have found you have only two strategies for maintainable unit tests around pre-existing private methods.
read more
Posts
Which Type of Tests Should You Write?
When test-driving a system, it can be tricky to know which type of test to use and when. Rather than talk about the testing pyramid, I want to focus on the questions we want answers to.
Below I have organized feature tests, integration tests and unit tests by the questions that they answer.
Is It Wired Together? Whenever I start working on a new feature for a system, I begin by writing a failing feature test.
read more
Posts
Testing Patterns in Ruby: Contract Testing
Maintain shared behavior of multiple implementations by making them pass the same tests.
Motivation When building a system, there may emerge a subsystem or class that has to share a baseline set of behavior with other implementations, while providing other non-functional requirements. The shared behavior can be shown to exist by using a contract test.
Example Test doubles are a great way to reduce overall speed of the test suite by only running tests against in-memory versions of external services.
read more
Posts
When Should You Refactor?
I find that there are two moments that best suit using refactoring; practicing TDD and adding new features.
As part of the TDD flow, we restructure the code we wrote in the last ten minutes, after the red and green stages. We iterate until we find a design that is the best we can think of at the moment, for the features we have now. The best designs follow the Four Simple Rules Of Design.
read more