Below you will find pages that utilize the taxonomy term “testing”
Posts
How to Randomize Tests in JUnit with Gradle
The ability to randomize the order of tests has always been a useful tool for diagnosing flaky tests as it exposes the interdependency between tests. However, until JUnit 5.8.0, you were only able to randomize the order of methods within a test class using MethodOrder$Random. Now you can also randomize the class order!
Lets setup version 5.8.0 of JUnit, and demonstrate how to run classes and methods randomly.
1. Setting up JUnit 5.
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#.
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 test this code?”
The key to testing private methods in any language is to test them through the public ones.
To this end, you have two strategies to try: “testing via the public interface”, or “move methods to a different class” and test them there.
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.
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.
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.