所以我通过ruby koans教程学习Ruby.在about_assert.rb脚本中,有一个关于assert_equal的注释, "断言平等的一些方法比其他方法更好"
这是代码
def test_a_better_way_of_asserting_equality
expected_value = 2
actual_value = 1 + 1
assert_equal expected_value, actual_value
end
Run Code Online (Sandbox Code Playgroud)
我的问题是,为什么
assert_equal expected_value, actual_value胜过
assert expected_value == actual_value
在Ruby的Test :: Unit中,如何获取当前test_方法的名称?在MiniTest中,这可以通过self.__name__,但它不适用于完整版本.
我正在使用此命令运行一些测试...
bundle exec ruby -Itest test/functional/*.rb
Run Code Online (Sandbox Code Playgroud)
在我的test/functional目录中,我有两个文件......
file_sets_controller_test.rb
user_sessions_controller_test.rb
Run Code Online (Sandbox Code Playgroud)
使用上面的命令,file_sets_controller_test.rb所有运行中的测试但是user_sessions_controller_test.rb根本没有运行 - 没有报告错误或其他输出.
但是,我可以直接运行该文件没问题,用这个......
bundle exec ruby -Itest test/functional/user_sessions_controller_test.rb
Run Code Online (Sandbox Code Playgroud)
这很好.
我知道另一个选择是使用rake test functionals,但与直接运行相比,这是非常慢的.
ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin11.4.2]
Rails 3.2.12
Run Code Online (Sandbox Code Playgroud)
这是我的Gemfile的一部分......
group :development, :test do
gem 'ansi'
gem 'turn'
gem 'minitest'
gem 'minitest-matchers'
end
Run Code Online (Sandbox Code Playgroud)
这是我的test_helper.rb......
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'turn/autorun'
Turn.config.ansi = true
require 'minitest/autorun'
class ActiveSupport::TestCase
fixtures :all
end
Run Code Online (Sandbox Code Playgroud)
据我所知,删除Turn和Minitest宝石并没有改变任何东西.
如何以正确的方式模拟或覆盖Kernel.system方法,以便在调用时:
system("some command")
Run Code Online (Sandbox Code Playgroud)
而不是执行命令,它执行一些预定义的代码?
我尝试将以下内容添加到我的Test类中:
module Kernel
def system
puts "SYSTEM CALL!!"
end
end
Run Code Online (Sandbox Code Playgroud)
但它没有按预期工作,而是在执行测试时运行系统调用.
Minitest允许您通过覆盖test_order来按顺序运行测试alpha.(您也可以使用该i_suck_and_my_tests_are_order_dependent!方法.)
执行此操作后,如何控制跨多个文件运行测试的顺序?
有没有办法从一个文件运行一些测试,然后切换到另一个文件?
查看源代码,似乎应该能够控制方法的排序方式.但是你如何指定这个顺序呢?
谷歌搜索选择一个清晰和最新的解决方案时,有太多不同的帖子......
我写了3个测试来检查不同的可能性
===========.测试1确定================
// helloJest.js
function sayHello() {
return "hello there jest"
}
module.exports = sayHello;
Run Code Online (Sandbox Code Playgroud)
// helloJestTest
const sayHello = require('../../src/client/js/helloJest');
test('string returning hello there jest', () => {//
expect(sayHello()).toEqual('hello there jest');
});
Run Code Online (Sandbox Code Playgroud)
===========.TEST 2 FAILING ================
// helloJest.js
function sayHello() {
return "hello there jest"
}
export default { sayHello }; // <= changed
Run Code Online (Sandbox Code Playgroud)
// helloJestTest
const sayHello = require('../../src/client/js/helloJest');
test('string returning hello there jest', () => {//
expect(sayHello()).toEqual('hello there jest');
});
TypeError: sayHello is not a function …Run Code Online (Sandbox Code Playgroud) testunit ×6
ruby ×5
testing ×2
unit-testing ×2
babel ×1
ecmascript-6 ×1
javascript ×1
jestjs ×1
methods ×1
minitest ×1
mocking ×1