Before/After Suite when using Ruby MiniTest

2019-01-17 19:23发布

Is there an alternative to RSpec's before(:suite) and after(:suite) in MiniTest?

I suspect that a custom test runner is in order, however I cannot imagine it is not a common requirement, so somebody has probably implemented in. :-)

8条回答
够拽才男人
2楼-- · 2019-01-17 20:01

Nice thing about minitest is its flexibility. I've been using a custom MiniTest Runner with a +before_suite+ callback. Something like in this example - Ruby Minitest: Suite- or Class- level setup?

And then tell minitest to use the custom runner

MiniTest::Unit.runner = MiniTestSuite::Unit.new
查看更多
【Aperson】
3楼-- · 2019-01-17 20:11

You can just place the code outside of the class.

This is what I do to have a banner.

require 'selenium-webdriver'
require 'minitest/test'
require 'minitest/autorun'

class InstanceTest < Minitest::Test

    def setup
    url     = ARGV.first
    @url    = self.validate_instance(url)
        @driver = Selenium::WebDriver.for :firefox
    end
查看更多
登录 后发表回答