使用Minitest测试控制器 [英] Testing controllers with Minitest

查看:90
本文介绍了使用Minitest测试控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Minitest查找测试控制器的示例,但是我只找到了一对,并且只需验证呈现了什么模板并返回成功"即可.这对我似乎没有太大帮助. Minitest是否用于测试控制器?

I'm trying to find examples of testing controllers with Minitest, but I've only found a couple and the just verify what template is rendered and that 'success' is returned. That doesn't seem very helpful to me. Is Minitest used to test controllers?

The Railscast( http://railscasts.com/episodes/327-minitest-with-rails)和我发现的其他几篇文章似乎使用Minitest进行模型测试,并使用Capybara进行集成测试.

The Railscast ( http://railscasts.com/episodes/327-minitest-with-rails ) and a couple other posts I've found seem to do model tests with Minitest and integration tests with Capybara.

控制器测试如何?可以用Minitest测试它们吗?如果是这样,是否有任何实际示例可以实际测试这些操作?经过数小时的搜索,我找不到任何东西,这似乎很奇怪.

What about controller tests? Can they be tested with Minitest? If so, are there any real-world examples that actually test the actions? It seems very odd that I can't find any after literally hours of searching.

我知道这很模糊,但是我试图决定是否应该使用RSpec或Minitest,但是在不知道如何使用Minitest真正测试控制器的情况下,我不知道它到底是不是一种选择但我一直在阅读一些有关它的普遍好评.

I know this is vague, but I'm trying to decide if I should go with RSpec or Minitest, but without having a clue how to truly test a controller with Minitest, I'm not seeing how it's even really an option, yet I keep reading some general rave reviews about it.

推荐答案

是的,您可以使用Minitest测试控制器.使用Minitest测试控制器与使用Test :: Unit测试控制器没有什么不同.支持您找到的所有示例,例如《 Rails指南》.

Yes, you can use Minitest to test a controller. Testing a controller using Minitest is no different than testing a controller using Test::Unit. Any examples you find, like the Rails Guide, are supported.

http://guides.rubyonrails.org/testing. html#functional-tests-for-your-controllers

这篇关于使用Minitest测试控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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