FAQ / knapsack_pro / General questions for knapsack_pro gem

How to split tests based on test level instead of test file level?

IMPORTANT: If you want to split one big test file (test file with long time execution) across multiple CI nodes then you can first check if knapsack_pro gem can auto split your slow test files for your test runner or you can see below tips:

A. Create multiple small test files

Create multiple small test files instead of one long running test file with many test cases. A lot of small test files will give you better test suite split results.

B. Use tags to mark set of tests in particular test file

Another way is to use tags to mark subset of tests in particular test file and then split tests based on tags.

This example is for knapsack_pro Regular Mode. You can also use knapsack_pro Queue Mode with tags.

Here is example of test file with specified tags for describe groups:


# spec/features/something_spec.rb
describe 'Feature' do
  describe 'something A', :tagA do
    it {}
    it 'another test' {}
  end

  describe 'something B', :tagB do
    it {}
  end

  describe 'something else' do
    it {}
  end
end

You need to create API token per each tag. In this example we need 3 different API tokens.

You need to run below commands for each CI node.


# run only tests with tagA
KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=api_key_for_tagA bundle exec rake "knapsack_pro:rspec[--tag tagA]"

# run only tests with tagB
KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=api_key_for_tagB bundle exec rake "knapsack_pro:rspec[--tag tagB]"

# run other tests without tag A & B
KNAPSACK_PRO_TEST_SUITE_TOKEN_RSPEC=api_key_for_tests_without_tags_A_and_B bundle exec rake "knapsack_pro:rspec[--tag ~tagA --tag ~tagB]"

# General questions for knapsack_pro gem
See questions outside of this category

Start using Knapsack Pro

Sign up and speed up your tests.