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.