【问题标题】:Asserting and Messages -Rails断言和消息 -Rails
【发布时间】:2014-04-11 19:06:51
【问题描述】:

因此,当我运行 rails 测试时,我想将内容打印到控制台,例如

Test1: passed
Test2: F1
Test3: F2

现在我有一些代码看起来像

test "the first test" do
    print "\nTest1: "
    assert true
    print "passed"
end

这对于通过的测试很有效,但我不知道如何让 Faliures 的计数器运行,因为一旦它断言为 false,测试就会结束。

目前我的输出看起来像这样......

Test0: passed.
Test1: F
Test2: F

感谢你们的时间!

【问题讨论】:

  • 只是为了了解一些上下文,你为什么要这样做?运行后TestUnit会给你一个失败和通过的总结
  • 我为之制作这个的人想要这样。因此,他们可以查看“F”后面的数字并知道是哪个错误,而不是计算 F 直到找到他们想要阅读的错误。

标签: ruby-on-rails ruby unit-testing testing


【解决方案1】:

您必须在断言发生之前手动进行检查

test "the first test" do
    print "\nTest1: "
    condition = false
    print "F1" unless condition
    assert condition
    print "Passed"
end

【讨论】:

  • 这将是 Test1: F1F
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-08-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-07
  • 2011-04-15
  • 2016-10-21
相关资源
最近更新 更多