Class MiniTest::Unit::TestCase
In: lib/minitest/unit.rb
lib/minitest/benchmark.rb
Parent: Object

Subclass TestCase to create your own tests. Typically you‘ll want a TestCase subclass per implementation class.

See MiniTest::Assertions

Methods

Included Modules

Guard MiniTest::Assertions

External Aliases

__send__ -> run_test

Public Class methods

Adds a block of code that will be executed before every TestCase is run. Equivalent to setup, but usable multiple times and without re-opening any classes.

All of the setup hooks will run in order after the setup method, if one is defined.

The argument can be any object that responds to call or a block. That means that this call,

    MiniTest::Unit::TestCase.add_setup_hook { puts "foo" }

… is equivalent to:

    module MyTestSetup
      def self.call
        puts "foo"
      end
    end

    MiniTest::Unit::TestCase.add_setup_hook MyTestSetup

The blocks passed to add_setup_hook take an optional parameter that will be the TestCase instance that is executing the block.

Adds a block of code that will be executed after every TestCase is run. Equivalent to teardown, but usable multiple times and without re-opening any classes.

All of the teardown hooks will run in reverse order after the teardown method, if one is defined.

The argument can be any object that responds to call or a block. That means that this call,

    MiniTest::Unit::TestCase.add_teardown_hook { puts "foo" }

… is equivalent to:

    module MyTestTeardown
      def self.call
        puts "foo"
      end
    end

    MiniTest::Unit::TestCase.add_teardown_hook MyTestTeardown

The blocks passed to add_teardown_hook take an optional parameter that will be the TestCase instance that is executing the block.

Returns a set of ranges stepped exponentially from min to max by powers of base. Eg:

  bench_exp(2, 16, 2) # => [2, 4, 8, 16]

Returns a set of ranges stepped linearly from min to max by step. Eg:

  bench_linear(20, 40, 10) # => [20, 30, 40]

Specifies the ranges used for benchmarking for that class. Defaults to exponential growth from 1 to 10k by powers of 10. Override if you need different ranges for your benchmarks.

See also: ::bench_exp and ::bench_linear.

Returns all test suites that have benchmark methods.

Call this at the top of your tests when you absolutely positively need to have ordered tests. In doing so, you‘re admitting that you suck and your tests are weak.

Public Instance methods

Runs before every test after setup. Use this to refactor test initialization.

Runs after every teardown. Use this to refactor test cleanup.

Runs the given work, gathering the times of each run. Range and times are then passed to a given validation proc. Outputs the benchmark name and times in tab-separated format, making it easy to paste into a spreadsheet for graphing or further analysis.

Ranges are specified by ::bench_range.

Eg:

  def bench_algorithm
    validation = proc { |x, y| ... }
    assert_performance validation do |n|
      @obj.algorithm(n)
    end
  end

Runs the given work and asserts that the times gathered fit to match a constant rate (eg, linear slope == 0) within a given threshold. Note: because we‘re testing for a slope of 0, R^2 is not a good determining factor for the fit, so the threshold is applied against the slope itself. As such, you probably want to tighten it from the default.

See www.graphpad.com/curvefit/goodness_of_fit.htm for more details.

Fit is calculated by fit_linear.

Ranges are specified by ::bench_range.

Eg:

  def bench_algorithm
    assert_performance_constant 0.9999 do |n|
      @obj.algorithm(n)
    end
  end

Runs the given work and asserts that the times gathered fit to match a exponential curve within a given error threshold.

Fit is calculated by fit_exponential.

Ranges are specified by ::bench_range.

Eg:

  def bench_algorithm
    assert_performance_exponential 0.9999 do |n|
      @obj.algorithm(n)
    end
  end

Runs the given work and asserts that the times gathered fit to match a straight line within a given error threshold.

Fit is calculated by fit_linear.

Ranges are specified by ::bench_range.

Eg:

  def bench_algorithm
    assert_performance_linear 0.9999 do |n|
      @obj.algorithm(n)
    end
  end

Runs the given work and asserts that the times gathered curve fit to match a power curve within a given error threshold.

Fit is calculated by fit_power.

Ranges are specified by ::bench_range.

Eg:

  def bench_algorithm
    assert_performance_power 0.9999 do |x|
      @obj.algorithm
    end
  end

Runs before every setup. Use this to refactor test initialization.

Runs after every test before teardown. Use this to refactor test initialization.

Takes an array of x/y pairs and calculates the general R^2 value.

See: en.wikipedia.org/wiki/Coefficient_of_determination

To fit a functional form: y = ae^(bx).

Takes x and y values and returns [a, b, r^2].

See: mathworld.wolfram.com/LeastSquaresFittingExponential.html

Fits the functional form: a + bx.

Takes x and y values and returns [a, b, r^2].

See: mathworld.wolfram.com/LeastSquaresFitting.html

To fit a functional form: y = ax^b.

Takes x and y values and returns [a, b, r^2].

See: mathworld.wolfram.com/LeastSquaresFittingPowerLaw.html

Return the output IO object

Have we hooked up the IO yet?

Returns true if the test passed.

Runs the tests reporting the status to runner

Runs before every test. Use this to refactor test initialization.

Enumerates over enum mapping block if given, returning the sum of the result. Eg:

  sigma([1, 2, 3])                # => 1 + 2 + 3 => 7
  sigma([1, 2, 3]) { |n| n ** 2 } # => 1 + 4 + 9 => 14

Runs after every test. Use this to refactor test cleanup.

Returns a proc that calls the specified fit method and asserts that the error is within a tolerable threshold.

[Validate]