Recently I’ve been looking into the source code of Minitest to find out if I can run some tests and then dynamically run another set of tests once the previous run is done. This would allow me to provide dynamically a list of tests to execute on my parallel CI nodes to run CI builds faster.
As you can see one of the steps is to clear examples with RSpec.clear_examples for the previous run to ensure the executed tests won’t affect the next list of tests we will run.
I was also looking if something similar exists in Minitest to ensure we have a pristine state of test runner before we run another set of test files. I step on Minitest::Runnable.reset method that could do it.
Digging into Minitest source code
I found out that Minitest has class method run that will start running the loaded test files.
Knowing that I could run tests with it. The first step thou was to ensure we will be able to load test files but I realized at the top of each of test file I have a line like:
and the test_helper.rb file was not found while I attempt to load test file so I had to first add a directory with my tests to load path to make above require work.
Running Minitest continuously and fetching test files from the Queue in a dynamic way
Digging into the source code of Minitest helped me to find out a way to run my tests in a more efficient way. I applied this to the knapsack_pro gem I’m working on.
You can see in the below video how dynamic tests allocation across CI nodes can save time and run test suite faster. Last week one of my users from https://angel.co tried the Queue Mode in knapsack_pro for Minitest and it helped him run CI builds faster. Maybe this will help you too. :)