我正在尝试为在测试/单元中运行的测试设置日志记录级别
require 'test/unit'
require 'logger'
class MyMath
def self.adder(a,b)
a+b
end
end
class Tester < Test::Unit::TestCase
$logger = Logger.new($stdout)
def test_adder()
$logger.info "Starting Test"
assert_equal(4, MyMath.adder(2,2) )
$logger.info "Ending Test"
end
end
输出是
Loaded suite ruby.test
Started
I, [2021-07-23T13:12:26.497311 #49542] INFO -- : Starting Test
I, [2021-07-23T13:12:26.497375 #49542] INFO -- : Ending Test
.
Finished in 0.000358 seconds.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
2793.30 tests/s, 2793.30 assertions/s
如何使其不打印日志消息?在它谈到的test::unit::ui::console::testrunner代码中
# Creates a new TestRunner for running the passed
# suite. If quiet_mode is true, the output while
# running is limited to progress dots, errors and
# failures, and the final result. io specifies
# where runner output should go to; defaults to
# STDOUT.
什么是安静模式,如何设置?
1条答案
按热度按时间ccrfmcuu1#
我认为您的问题是需要相应地设置日志记录器的日志级别。
https://ruby-doc.org/stdlib-2.4.0/libdoc/logger/rdoc/logger.html
不确定是否使用了任何框架,以便只需在测试中设置日志级别,如