我想在minitest ruby​​中的所有测试之前调用def setup方法

时间:2017-04-07 10:55:08

标签: ruby minitest selenium-ruby

这是我的代码

class TestLogin < MiniTest::Test

  def setup
    @driver=Selenium::WebDriver.for :firefox
    @driver.manage.window.maximize
    @driver.navigate.to "http://google.com"
  end

  def test_case1 
    puts "testcase1"
  end

  def test_case2
    puts "testcase2"
  end
end

我想在开始时为两个测试用例运行一次setup方法。

1 个答案:

答案 0 :(得分:2)

您可以使用minitest-hooks gem和before_all之类的内容:

require "minitest/autorun"
require 'minitest/hooks/test'

class TestLogin < MiniTest::Test
  include Minitest::Hooks

  def before_all
    puts "setup .."
  end

  def test_case1
    puts "testcase1"
  end

  def test_case2
    puts "testcase2"
  end
end

现在,当您运行测试时,您应该看到类似的内容:

Run options: --seed 58346

# Running:

setup ..
testcase1
.testcase2
.

Finished in 0.001259s, 1588.7504 runs/s, 0.0000 assertions/s.

2 runs, 0 assertions, 0 failures, 0 errors, 0 skips