Skip to content

Commit

Permalink
Skip benchmark tests (#152)
Browse files Browse the repository at this point in the history
* Add test case with benchmarks

* Skip benchmark

* Support extracting metadata from benchmark file

* Skip benchmark tests
  • Loading branch information
ErikSchierboom authored Mar 6, 2024
1 parent 3477944 commit 661c74a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/test_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def run
Minitest::PrideIO.pride!

Dir.glob(File.join(input_path, "*_test.rb")).sort.each do |test_file|
next if test_file.end_with?("_benchmark_test.rb")

reporter.set_metadata(test_file, ExtractMetadata.(test_file))

begin
Expand Down
1 change: 1 addition & 0 deletions tests/benchmarks/expected_results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":2,"status":"pass","message":null,"tests":[{"name":"No name given","test_code":"assert_equal \"One for you, one for me.\", TwoFer.two_fer","status":"pass"},{"name":"A name given","test_code":"assert_equal \"One for Alice, one for me.\", TwoFer.two_fer(\"Alice\")","status":"pass"},{"name":"Another name given","test_code":"assert_equal \"One for Bob, one for me.\", TwoFer.two_fer(\"Bob\")","status":"pass"}]}
5 changes: 5 additions & 0 deletions tests/benchmarks/two_fer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class TwoFer
def self.two_fer(name = "you")
"One for #{name}, one for me."
end
end
11 changes: 11 additions & 0 deletions tests/benchmarks/two_fer_benchmark_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'minitest/autorun'
require 'minitest/benchmark'
require_relative 'two_fer'

class TwoFerBenchmarkTest < Minitest::Benchmark
def bench_two_fer
assert_performance_linear 0.9999 do |n| # n is a range value
TwoFer.two_fer
end
end
end
20 changes: 20 additions & 0 deletions tests/benchmarks/two_fer_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'minitest/autorun'
require_relative 'two_fer'

# Common test data version: 1.2.0 4fc1acb
class TwoFerTest < Minitest::Test
def test_no_name_given
# skip
assert_equal "One for you, one for me.", TwoFer.two_fer
end

def test_a_name_given
skip
assert_equal "One for Alice, one for me.", TwoFer.two_fer("Alice")
end

def test_another_name_given
skip
assert_equal "One for Bob, one for me.", TwoFer.two_fer("Bob")
end
end

0 comments on commit 661c74a

Please sign in to comment.