Unit::Test 与 Rspec 之间的差异 [英] Difference between Unit::Test versus Rspec

查看:49
本文介绍了Unit::Test 与 Rspec 之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Test::UnitRspec 感兴趣.

I am interested in Test::Unit and Rspec.

有人可以向我解释两者之间的主要区别是什么 - 就它们运作的原则而言.

Could someone explain me what is the main difference between the two - in terms of principles on which they operate.

推荐答案

Test::Unit 更类似于 JUnit 这样的经典 TDD 工具.测试被编写为类(因为它是在 Java/C++ 中完成的).

Test::Unit is more akin to a classic TDD tool like JUnit. Tests are written as classes (because that's how it was done in Java / C++).

Test::Unit 对于那些习惯于经典测试工具的人来说更容易上手.

Test::Unit is more approachable by those who are used to classic testing tools.

Test::Unit 是内置的 Ruby 测试库,但被认为已死(开发已停止).它已被 Minitest 取代.

Test::Unit was the built in Ruby testing library but is considered dead (development has ceased). It has been superceeded by Minitest.

require_relative "simple_number"
require "test/unit"

class TestSimpleNumber < Test::Unit::TestCase
  def test_add
    assert_equal(4, SimpleNumber.new(2).add(2) )
  end
  def test_multiply
    assert_equal(6, SimpleNumber.new(2).multiply(3) )
  end
end

RSpec 是一种领域特定语言,它利用 ruby​​ 语言的灵活性来创建更具可读性"的测试.

RSpec is a domain specific language which uses the flexibility of the ruby language to create tests which are "more readable".

RSpec 的早期版本在这方面做得有点过火,并且对核心 Ruby 类进行了猴子补丁.

Earlier versions of RSpec took this a bit too far and monkeypatched core Ruby classes.

RSpec 更倾向于行为驱动开发的哲学,在这种哲学中,您描述应用中组件的行为,而 TDD 则将应用分成最小的组件.

RSpec is more oriented towards the philosophy of Behavior Driven Development where you describe the behavior of the components in your app vs TDD where you slice the app into its smallest components.

require "spec_helper"
require "lib/simple_number"

describe SimpleNumber do 
  describe "#add" do
    it "adds a value to the sum" do
      expect(SimpleNumber.new(2).add(2)).to eq(4)
    end 
  end
  describe "#multiply" do
    it "multiplies with the value" do
      expect(SimpleNumber.new(2).multiply(3)).to eq(6)
    end 
  end
end

哪个更好?

这是一个意见问题.

Minitest 最近有点复苏,因为它被认为更快、更简单.然而,测试可能非常简洁,真正降低套件速度的是集成测试和数据库 IO.

Minitest has recently had a bit of a resurgence as it is perceived as faster and simpler. However tests can be extremely terse, and what really slows down a suite is integration tests and database IO.

不幸的是,许多新的转换者编写测试会导致任何 Java 开发人员畏缩读起来像长篇大论,每个测试用例有很多断言.

And unfortunately many of the new converts write tests which would cause any Java developer to cringe which read like long ramblings with many assertions per test case.

编写良好的 RSpec 测试套件(或规范套件)更具可读性和易于导航.当规范失败时,很容易将其与应用程序中的实际错误联系起来.当然也有很多套房正好相反.

A well written RSpec test suite (or spec suite) is both more readable and easy to navigate. When a spec fails it is pretty easy to tie it to what actually went wrong in the application. Of course there are many suites which are the exact opposite.

Minitest 非常灵活,甚至可以与规范风格的语法一起使用.它开箱即用非常稀疏,不包括丰富的断言库和像 RSpec 这样的模拟库.虽然您可以插入任何东西,但您仍然需要让所有活动部件协同工作.

Minitest is extremely flexible and can even be used with a spec style syntax. Its very sparse out of the box and does not include a rich assertions library and a mocking library like RSpec. While you can plug anything in you still need to get all the moving parts to work together.

RSpec 有更好的测试运行程序和出色的文档.

RSpec has a much better test runner and superior documentation.

这篇关于Unit::Test 与 Rspec 之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆