使用 Rake 运行 Ruby 单元测试

编程入门 行业动态 更新时间:2024-10-23 05:32:41
本文介绍了使用 Rake 运行 Ruby 单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在研究使用 Rake 构建工具来自动运行单元测试.我在网上搜索,但所有的例子都是使用 rails 的.我通常只编写小型命令行程序或简单的 Sinatra 应用程序.

I was investigating using the Rake build tool to automate running unit tests. I searched the web, but all the examples were for using rails. I usually just write small command-line programs or simple Sinatra applications.

所以我想出了以下(可能是糟糕的)解决方案,它只是模拟我在命令行上所做的事情:(我只是以一个单元测试为例.)

So I came up with the following (probably bad) solution that just emulates what I would do on the command-line: (I just ran one unit test as an example.)

desc 'Run unit tests' task :test do sh 'ruby -I lib test/test_entry.rb' end task :default => :test

它有效,但我不禁想到一定有更好的方法,只是编写 require 'test/test_entry.rb' 不起作用.我遇到 require 问题,Ruby 找不到 lib 目录,所有文件都在那里.

It works, but I can't help thinking there must be a better way, just writing require 'test/test_entry.rb' doesn't work. I get require problems, Ruby can't find the lib directory, where all the files are.

推荐答案

Use Rake::TestTask rake.rubyforge/classes/Rake/TestTask.html.把它放到你的 Rake 文件中,然后运行 ​​rake test:

Use Rake::TestTask rake.rubyforge/classes/Rake/TestTask.html . Put this into your Rake file and then run rake test:

require 'rake/testtask' Rake::TestTask.new do |t| t.libs << "test" t.test_files = FileList['test/test*.rb'] t.verbose = true end

更多推荐

使用 Rake 运行 Ruby 单元测试

本文发布于:2023-10-31 04:14:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1544971.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单元测试   Rake   Ruby

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!