Can Nightwatch be used to test Rails?

那年仲夏 提交于 2020-01-05 04:21:09

问题


A contractor for our startup installed the Selenium-based Nightwatch testing framework, since our stack is React-heavy. But he told me that it could even be used to test our Rails code. A new contractor said, to the contrary, that Nightwatch couldn't do unit tests of our Rails controllers and models (which makes sense to me).

Who is right? Do you suppose the first programmer had in mind just that we would do end-to-end testing (certain inputs lead to certain outputs), and that we need not test the details of the Rails code? Do we, as I suspect and as the new contractor asserts, need RSpec or some other Ruby-based testing framework to handle our Rails code, if we want to be a TDD shop?


回答1:


Yes it can be used to test Rails. But only from the outside (only through the Browser). So no Unit/Controller/View Tests. You'll need MiniTest or Rspec for those.

My two cents (also see comment by @SteveCarey): Since I prefer to stick with what comes with Rails and use as little external tools as possible:

Have a look at System Tests that have been introduced with Rails 5.1 or, if you are on a older version, see if you can write those tests using Capybara/Integration Tests.

Update:

You can find more details on testing framework here: http://guides.rubyonrails.org/v4.1/testing.html#brief-note-about-minitest

It was Test::Unit and nowadays is Minitest. But the basics are the same so it does not really matter.

Another popular testing framework is RSpec. Which you can use instead of Minitest/TestUnit if you want to. I prefer Minitest but there are pros and cons for both frameworks.

Rails 4.2 came with Unit-tests, Functional/Controller-tests and Integration-tests. The built in thing that resembles Nightwatch the most are Integration-tests: http://guides.rubyonrails.org/v4.1/testing.html#integration-testing

You can also look at libraries such as Capybara (https://github.com/teamcapybara/capybara) which calls itself an Acceptance Test framework. It integrates nicely with TestUnit/Minitest/Rspec.



来源:https://stackoverflow.com/questions/45047769/can-nightwatch-be-used-to-test-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!