4
 assert_nothing_raised do
   @board.make_move(0,0,Board::HUMAN)
 end

和文档说:

Passes if block does not throw anything.

Example:

 assert_nothing_thrown do
   [1, 2].uniq
 end

我的 make_move 方法:

def make_move(x, y, player)
    return false
 end

我得到错误:

test_can_make_valid_move_in_the_first_row(BoardTest):
ArgumentError: wrong number of arguments (1 for 2)
4

2 回答 2

4

以下代码对我有用。对你起作用吗?

require 'test/unit'
require 'test/unit/ui/console/testrunner'

class MyTestClass < Test::Unit::TestCase
  def test_something
    assert_nothing_raised do
      p 'hi'
    end
  end
end

Test::Unit::UI::Console::TestRunner.run(MyTestClass)

我认为您正确使用了 assert_nothing_raised 。尝试更换

@board.make_move(0,0,Board::HUMAN)

用更简单的东西,比如

p 'hi'

看看这是否有效。还可以尝试注释掉测试中的所有其他代码。

于 2011-01-30T16:43:18.637 回答
3

可以说你永远不应该使用assert_nothing_raised,因为它实际上并没有测试任何东西。看:

http://blog.zenspider.com/blog/2012/01/assert_nothing_tested.html

我在这里发布了一些进一步的想法:

为什么 MiniTest::Spec 没有 wont_raise 断言?

于 2012-09-19T16:50:24.773 回答