Nightwatch可以用来测试Rails吗? [英] Can Nightwatch be used to test Rails?

查看:61
本文介绍了Nightwatch可以用来测试Rails吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的初创公司的承包商安装了基于Selenium的Nightwatch测试框架,因为我们的堆栈重于React.但是他告诉我,它甚至可以用来测试我们的Rails代码.相反,一个新承包商说Nightwatch无法对我们的Rails控制器和模型进行单元测试(这对我来说很有意义).

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).

谁是对的?您是否认为第一位程序员只是想到我们将进行端到端测试(某些输入导致某些输出),并且我们不需要测试Rails代码的细节?我想并像新承包商所说的那样,如果我们想成为TDD商店,是否需要RSpec或其他基于Ruby的测试框架来处理我们的Rails代码?

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?

推荐答案

是的,它可以用于测试Rails.但只能从外部(仅通过浏览器).因此,没有单元/控制器/视图测试. 您将需要使用MiniTest或Rspec.

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.

我的两分钱(另请参阅@SteveCarey的评论):因为我更喜欢坚持使用Rails附带的东西,并尽可能少使用外部工具:

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:

看看Rails 5.1引入的系统测试,或者,如果您使用的是旧版本,请查看是否可以使用Capybara/集成测试编写这些测试.

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.

更新:

您可以在此处找到有关测试框架的更多详细信息: http://guides.rubyonrails.org/v4.1/testing.html#brief-note-about-minitest

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

它是Test :: Unit,如今是Minitest.但是基本知识是相同的,因此并不重要.

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

另一个流行的测试框架是RSpec.如果需要,可以使用它代替Minitest/TestUnit.我更喜欢Minitest,但两种框架都有优缺点.

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附带了单元测试,功能/控制器测试和集成测试.最类似于Nightwatch的内置对象是集成测试: http: //guides.rubyonrails.org/v4.1/testing.html#integration-testing

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

您还可以查看Capybara之类的库( https://github.com/teamcapybara/capybara)本身称为验收测试框架.它与TestUnit/Minitest/Rspec很好地集成.

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.

这篇关于Nightwatch可以用来测试Rails吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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