How to organize minitest/unit tests?

后端 未结 3 1653
孤独总比滥情好
孤独总比滥情好 2021-02-04 23:39

After using RSpec for several projects, I\'m giving minitest/unit a go. I\'m liking it so far, but I miss using describe/context blocks to group my tests/specs in a logical way.

3条回答
  •  梦如初夏
    2021-02-05 00:11

    You can also throw multiple classes into one test file:

    module PizzaTest
      class Isolation < ActiveSupport::TestCase
        test "is awesome by default" do
          assert Pizza.new.awesome?
        end
      end
    
      class Integration < ActiveSupport::TestCase
        fixtures :all
    
        test "is awesome too" do
          pizzas('one-with-everything').awesome?
        end
      end
    end
    

    and even nest test classes:

    class PizzaTest < ActiveSupport::TestCase
      test "is awesome by default" do
        assert Pizza.new.awesome?
      end
    
      class Integration < ActiveSupport::TestCase
        fixtures :all
    
        test "is awesome too" do
          assert pizzas('one-with-everything').awesome?
        end
      end
    end
    

提交回复
热议问题