How to configure minitest for performance and manually create / delete fixtures

My problems:

  • The client database is located in the machine through the VPN, so my tests are very slow (about 30-40 seconds each)
  • This database is not completely suitable for my application, and my data is associated with data that was already in the database
  • Composite primary keys are present in old database tables, and informix adapter does not support it for fixtures

What I use:

  • Ruby on Rails 4.2.5
  • Jruby 9.0.1.0
  • Informix Database Through JDBC Connection
  • Minitest
  • MiniTest-o

What i have done so far:

  • Testing time was reduced after 5-10 seconds with Devise.stretches = 1and configurations Rails.logger.level = 4.
  • fixture , , , , , . , .
  • , , (self.use_transactional_fixtures = false), , , .
  • reset " " , , , , , . " ", :

    class ActiveRecord::FixtureSet
      class << self
        alias :orig_create_fixtures :create_fixtures
      end
    
      def self.create_fixtures f_dir, fs_names, *args
        reset_cache
    
        #Deleting my fixture data
        People.delete_all
    
        orig_create_fixtures f_dir, fs_names, *args
      end
    end
    

delete_all .

, , 8 .

:

ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require "rails/test_help"
require 'minitest/autorun'
require 'minitest/reporters'

Minitest.backtrace_filter = Minitest::BacktraceFilter.new

# Load support files
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }

ActiveSupport::TestCase.class_eval do
  extend MiniTest::Spec::DSL

  # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
  fixtures :all

  self.use_transactional_fixtures = false

  Devise.stretches = 1
  Rails.logger.level = 4

  reporter_options = {color: true, slow_count: 5}
  Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(reporter_options)]
end

- ? ? ?

+4

Source: https://habr.com/ru/post/1618313/


All Articles