3

这是我的代码

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

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

4

1 回答 1

5

您可以将minitest-hooksgem 与以下内容一起使用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
于 2017-04-07T11:55:12.193 回答