简体   繁体   English

如何使用单元样式配置minitest以进行集成测试

[英]How to configure minitest for integration tests using the unit style

I found resources for configuring Rails to use Minitest. 我找到了配置Rails以使用Minitest的资源。 Most of the resources, unfortunately, assume the use of Minitest Spec for all the test types or, in the best case, at least for the integration test. 遗憾的是,大多数资源都假设Minitest Spec适用于所有测试类型,或者在最好的情况下,至少用于集成测试。

I may be "vintage", but I feel the assertions ala test:unit work better for me than the rspec style. 我可能是“复古”,但我觉得断言是一个测试:单位工作对我来说比rspec风格更好。 I would use MiniTest::Unit declaration style, together with Capybara, to run the integration tests. 我将使用MiniTest :: Unit声明样式与Capybara一起运行集成测试。

I am interested in seeing an example of minitest_helper.rb and some_model_integration_test.rb to understand the relevant configuration elements I need to put in place to make the integration test work nicely with Capybara. 我有兴趣看到minitest_helper.rb和some_model_integration_test.rb的示例,以了解我需要采用的相关配置元素,以使集成测试与Capybara完美配合。

Can somebody explain how to configure Rails for this? 有人可以解释如何为此配置Rails吗?

My articles_integration_test.rb : 我的articles_integration_test.rb

require 'test_helper'

class ArticlesIntegrationTest < IntegrationTest

  def test_shows_article_title
    article = Article.create!(title: 'Foo bar')
    visit article_path(article)
    assert page.has_content?('Foo bar')
  end

end

My test_helper.rb : 我的test_helper.rb

ENV["RAILS_ENV"] = "test"
require File.expand_path("../../config/environment", __FILE__)
require "minitest/autorun"
require "capybara/rails"
require "active_support/testing/setup_and_teardown"

class IntegrationTest < MiniTest::Unit::TestCase
  include Rails.application.routes.url_helpers
  include Capybara::DSL
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM