6

For example, in Jasmine, you can do this:

describe('Person', function () {
  describe('movement methods', function () {
    it('#run', function () {

    });
    it('#jump', function () {

    });
  });
});

With Minitest, it seems that you can't have a "movement methods" category. You'd have to just do:

class PersonTest
  def test_run
  end

  def test_jump
  end
end

Is there a way to nest in Minitest?

Adam Zerner
  • 17,797
  • 15
  • 90
  • 156

1 Answers1

6

Yes you can. You can do something like this (not the prettiest):

class Person < ActiveSupport::TestCase
  class MovementMethods < ActiveSupport::TestCase
    test "#run" do
      # something
    end

    test "#jump" do
      # something
    end
  end
end

Also consider using minitest/spec and you can write your tests cases more comparable to the Jasmine snippet:

require 'minitest/spec'

describe Person do
  describe 'movement methods' do
    it '#run' do
      # something
    end

    it '#jump' do
      # something
    end
  end
end
jdgray
  • 1,863
  • 1
  • 11
  • 19
  • 3
    **Note**: `MovementMethods` will act as a _parallel_ TestCase instead of a _nested_ one. This means; a `setup` inside `Person` will be **never** executed for any test inside `MovementMethods`. – Francute Sep 18 '18 at 20:24
  • As mentioned here: https://stackoverflow.com/a/29853967 If we make `MovementMethods` inherit the `Person` class, the setup inside `Person` will be executed for tests inside `MovementMethods`. – hungmi Dec 07 '21 at 07:47
  • If there are instance variables created in the parent test class, how would the child test class use them? – tamouse Aug 02 '22 at 16:35