Skip to content

Instantly share code, notes, and snippets.

@emanuil
Created January 25, 2017 09:05
Show Gist options
  • Save emanuil/1f3bf1d8665b70861eb428273d412ae1 to your computer and use it in GitHub Desktop.
Save emanuil/1f3bf1d8665b70861eb428273d412ae1 to your computer and use it in GitHub Desktop.
A tool to count the number of test cases per feature file in order to evenly distribute them then running in parallel
require 'gherkin/parser'
require 'gherkin/pickles/compiler'
@test_case_files = []
@tags_to_ignore = ['@no_parallel', '@wip', '@bug', '@live', '@real', '@mobile', '@site']
all_feature_files = Dir.glob("./**/*.feature")
all_feature_files.each do |feature_file|
contents = File.read(feature_file)
parser = Gherkin::Parser.new
gherkin_document = parser.parse(contents)
pickles = Gherkin::Pickles::Compiler.new.compile(gherkin_document, feature_file)
@test_cases_count = pickles.count
pickles.each do |test_case|
test_case[:tags].each do |tag|
if @tags_to_ignore.include? tag[:name]
@test_cases_count -= 1
break
end
end
end
if @test_cases_count > 0
@test_case_files.push({name: feature_file[2..-1], test_case_count: @test_cases_count})
end
end
sorted = @test_case_files.sort_by { |k| k[:test_case_count] }.reverse
puts sorted
@emanuil
Copy link
Author

emanuil commented Jan 25, 2017

For more information read this blog post: Running Test In Parallel - Optimal Number Of Threads

@onlybiju
Copy link

Do you have something similar to this in JAVA?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment