Ruby Unit Test Framework Testunit Alternative minitest Introduction to _ruby topics

Source: Internet
Author: User
Tags gtk advantage

Minitest, a new generation of ruby testing framework, has become the built-in test framework for Ruby 1.9, and it is said to be the default test framework for Rails 4, promising.

Minitest Why is the latest Ruby and Rails preferred, and what are the attractions?

Ruby 1.8 era, the default test framework for Ruby and Rails is Testunit,testunit history, its biggest problem is too slow, too bloated, it contains a bunch of now rarely used third-party libraries, such as GTk v1, GTk v2, Fxruby, Another big problem is that it lacks some basic test features, such as the test style of the spec DSL, such as mock support, and so on.

Minitest is equivalent to a large reconfiguration of the Testunit, which inherits most of the Testunit usage, eliminates improper dependencies in testunit, and adds basic test features such as spec and mocks, which become quite fast and neat overall.

In the Ruby and Rails world, there is a test framework that is Rspec and even more widely used than testunit and minitest, why doesn't it become the default framework? I think Minitest's biggest advantage over Rspec is simplicity and continuity, and Rspec is much more complex and, of course, more powerful than minitest, and has the advantage of simplicity and continuity (relative to testunit) for the built-in Ruby class library. For rails, the father of rails, DHH, and Rspec have been looking at it, and I think that's the biggest reason rails chose minitest, haha.

Minitest Use Example

If you have used testunit,minitest very simply, here is a test of Hello world

Copy Code code as follows:

Class Hellowold
def Get_word
"Hello world!"
End
End

Test code

Copy Code code as follows:

Require ' Minitest/autorun '

Class Hellowoldtest < Minitest::unit::testcase
def Test_get_word
Assert_equal "Hello world!", HelloWold.new.get_word
End
End

Test code, Spec style

Copy Code code as follows:

Require ' Minitest/autorun '

Describe Hellowold do
It ' should return Hello World ' do
HelloWold.new.get_word.must_equal "Hello world!"
End
End

If you want to use minitest in a rails project, you can use the Gem minitest-rails, and after using Minitest-rails, the rails generator generated test is converted to Minitest style code.

Summarize

Minitest is quite simple and fast, it continues testunit usage, it's very fast, and it offers some great features that are very good to try out, no wonder it's the best choice for the latest Ruby and Rails, and I intend to use it in the future.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.