How do I effectively force Minitest to run my tests in order?

前端 未结 5 1255
走了就别回头了
走了就别回头了 2021-01-18 04:34

I know. This is discouraged. For reasons I won\'t get into, I need to run my tests in the order they are written. According to the documentation, if my test class (we\'ll c

5条回答
  •  北荒
    北荒 (楼主)
    2021-01-18 05:30

    The best way to interfere in this chain may be to override a class method runnable_methods:

    def self.runnable_methods
      ['run_first'] | super | ['run_last']
    end
    
    #Minitest version:
    def self.runnable_methods
      methods = methods_matching(/^test_/)
    
      case self.test_order
      when :random, :parallel then
        max = methods.size
        methods.sort.sort_by { rand max }
      when :alpha, :sorted then
        methods.sort
      else
        raise "Unknown test_order: #{self.test_order.inspect}"
      end
    end
    

    You can reorder test any suitable way around. If you define your special ordered tests with

    test 'some special ordered test' do 
    end
    

    , don't forget to remove them from the results of super call.

    In my example I need to be sure only in one particular test to run last, so I keep random order on whole suite and place 'run_last' at the end of it.

提交回复
热议问题