Ruby on rails 为什么在运行测试时Rails会创建许多测试模式?
当我在我的模型上运行一些测试时,Rails正在MySQL上创建另外四个测试模式。因此,在运行:Ruby on rails 为什么在运行测试时Rails会创建许多测试模式?,ruby-on-rails,testing,Ruby On Rails,Testing,当我在我的模型上运行一些测试时,Rails正在MySQL上创建另外四个测试模式。因此,在运行:$bin/rails test之后,我得到了由rails生成的这四个模式 我还有blog\u development,没关系 我进行了迁移,填充了装置,并编写了一个示例测试。我这里有一个示例应用程序: 下面是我的一些代码: 迁移 试验 需要“测试助手” 类ArticleTest
$bin/rails test
之后,我得到了由rails生成的这四个模式
我还有blog\u development
,没关系
我进行了迁移,填充了装置,并编写了一个示例测试。我这里有一个示例应用程序:
下面是我的一些代码:
迁移
试验
需要“测试助手”
类ArticleTest
我的环境
- MySQL:8.0.24(与Docker一起运行)
- 轨道:轨道6.1.3.1
- RVM版本:RVM 1.29.12李>
- Ruby版本:Ruby 3.0.0p0(2020-12-25修订版95aff21468)[x86_64-linux]李>
parallelize(工人:处理器的数量)
这是版本6的core Rails中引入的一个特性,它创建独立的测试模式,以便多个测试可以并行运行,而不会干扰彼此的数据库访问
有关此功能的详细信息,请参阅上的和该功能的概述。从文档中:
对于每个进程,将创建一个新的数据库,其后缀为工作者编号
test-database-0
test-database-1
就这样!谢谢最后一个问题。你知道为什么当我运行
rake db:drop
或rake db:reset
时,Rails不删除这些数据库(blog\u test-0,blog\u test-1…
)?数据库blog\u development
和blog\u test
被删除。
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
test-database-0
test-database-1