当我在我的模型上运行一些测试时,Rails将在MySQL上再创建四个测试模式。因此,在运行:$ bin/rails test之后,Rails生成了这四种模式。

我也有blog_development,没关系.
我做了迁移,填充了固定装置,并编写了一个示例测试。这里有一个示例应用程序:https://github.com/rgiaviti/poc-so-rails-creating-many-test-schemas
下面是我的一些代码:
迁徙
class CreateArticles < ActiveRecord::Migration[6.1]
def up
create_table :articles do |t|
t.string :title, null: false
t.text :body, null: false
t.timestamps
end
end
def down
drop_table :articles
end
end
class CreateComments < ActiveRecord::Migration[6.1]
def up
create_table :comments do |t|
t.references :article, null: false
t.text :body, null: false
t.timestamps
end
add_foreign_key :comments, :articles
end
def down
remove_foreign_key :comments, :articles
drop_table :comments
end
end固定装置
article-1:
title: This is the Article 1
body: Lorem ipsum dolor sit amet, consectetur adipiscing elit. In in erat tortor. Proin et dolor vitae erat blandit molestie. Ut vehicula finibus felis, tempor accumsan justo faucibus vitae
article-2:
title: This the Article 2
body: Lorem ipsum dolor sit amet, consectetur adipiscing elit. In in erat tortor. Proin et dolor vitae erat blandit molestie.
comment-1:
article: article-1
body: A Comment
comment-2:
article: article-1
body: "Some Comment"
comment-3:
article: article-2
body: Comment for other article测试
require "test_helper"
class ArticleTest < ActiveSupport::TestCase
test "should not save article without title" do
article = Article.new
article.body = "Body for an Article"
assert_not article.save
end
end我的环境
发布于 2021-04-25 21:20:26
在您的test/test_helper.rb中有以下指令,我认为它是初始默认测试套件创建的一部分:
parallelize(workers: :number_of_processors)这是一个在版本6的核心Rails中引入的特性,它创建独立的测试模式,这样多个测试可以并行运行,而不会干扰彼此的数据库访问。
有关这方面的更多信息,请参见Rails文档和BigBinary上特性的编写。从医生那里:
对于每个进程,将创建一个新的数据库,其后缀为员工编号。 测试数据库-0测试-数据库-1
https://stackoverflow.com/questions/67258165
复制相似问题