- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
使用内置的 Ruby Minitest 框架,有没有办法在整个套件运行之前运行一些代码,甚至在整个 TestClass 运行之前运行一次?我在 this question 的答案中看到Test::Unit::after_tests 可用于在运行所有测试后运行代码;是否有类似的方法在所有测试运行之前运行代码?
我想使用此功能在测试运行前初始化测试数据库,并在测试全部运行后将其拆除。
谢谢!
最佳答案
这是从 MiniTest 修改而来的 docs (在可自定义的测试运行器类型下)。
class Burger
def initialize
puts "YOU CREATED A BURGER"
end
def has_cheese?
true
end
def has_pickle?
false
end
end
gem 'minitest'
require 'minitest/unit'
MiniTest::Unit.autorun
class MyMiniTest
class Unit < MiniTest::Unit
def before_suites
# code to run before the first test
p "Before everything"
end
def after_suites
# code to run after the last test
p "After everything"
end
def _run_suites(suites, type)
begin
before_suites
super(suites, type)
ensure
after_suites
end
end
def _run_suite(suite, type)
begin
suite.before_suite if suite.respond_to?(:before_suite)
super(suite, type)
ensure
suite.after_suite if suite.respond_to?(:after_suite)
end
end
end
end
MiniTest::Unit.runner = MyMiniTest::Unit.new
class BurgerTest < MiniTest::Unit::TestCase
def self.before_suite
p "hi"
end
def self.after_suite
p "bye"
end
def setup
@burger = Burger.new
end
def test_has_cheese
assert_equal true, @burger.has_cheese?
end
def test_has_pickle
assert_equal false, @burger.has_pickle?
end
end
请注意,我包含了 gem 'minitest'
以使用 gem 而不是没有 MiniTest::Unit.runner
方法的捆绑版本。这是输出。
Run options: --seed 49053
# Running tests:
"Before everything"
"hi"
YOU CREATED A BURGER
.YOU CREATED A BURGER
."bye"
"After everything"
Finished tests in 0.000662s, 3021.1480 tests/s, 3021.1480 assertions/s.
2 tests, 2 assertions, 0 failures, 0 errors, 0 skips
所以它调用 #setup
两次,但是 .before_suite
和 .after_suite
只调用一次,我想这就是你要找的。
关于 ruby 迷你测试 : Suite- or Class- level setup?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6756488/
运行下面的 junit 会引发异常。 import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit
我想用 JUnit 4 启动一些 Suite 类,使用另一个 Suite 类。我有一个包的以下测试套件: package com.manuel.package1; import org.junit.r
我在另一个包中有一个数组列表,如下所示: String [ ] classes= {"SuiteTest1", "SuiteTest2"} 如何获取这些类并设置@SuiteClasses({})? p
我想学习 Spring 。在 STS(Spring Tool Suite)3 的情况下,有“Spring legacy Project”。 4 有一个“Spring Starter Project”,
正在尝试在客户端和服务器之间建立 SSL 连接。但每当我尝试从客户端连接时,我的服务器上都会收到 javax.net.ssl.SSLHandshakeException: no cipher suit
我正在使用全新安装的 STS 3.8.3,但无法将 JPA 方面添加到 EJB 项目: 如果我尝试创建 JPA 项目,则找不到该选项: 我确信这些曾经在 STS 中可用。我错过了什么? 最佳答案 我们
所以我一直在尝试使用我的手机通过 burp 获取请求/SSL。基本上我多次非常仔细地遵循这些步骤: Configuring your Browser to work with Burp Configu
任何机构都在他们的商店中使用 Talend SOA Suite。 如果我没记错的话,它与 Oracle SOA Suite 和 Service Bus 相比如何,因为这两个产品都实现了 EIP 模式?
我试图改变 Pivotal tc Server Developer 3.0 版的日志记录,我发现启动服务器的 java 进程从不读取 catalina base 中的 logging.properti
让我们假设我有一个相当大的组织 Spring Tool Suite (STS) 用户。这些用户正在使用一些过时的 STS 版本(例如 3.1.0)。 将这些用户升级到最新的 STS+Eclipse 的
我正在使用 DevExpress 制作的 XtraGrid Suite。我找不到任何功能来执行此操作,但我很好奇您是否可以将按钮或超链接添加到网格单元格。 上下文:我有一个事件列表。每个事件都有时间、
我希望将SPF和DKIM添加到MailChimp的域中。 该域正在通过G Suite运行,并具有以下SPF的TXT记录: v=spf1 include:_spf.google.com ~all 该域还
The before and after hook documentation on Relish仅显示 before(:suite) 在 before(:all) 之前调用。 我什么时候应该使用其中
有一个Juice Shop易受攻击的应用程序,可作为docker镜像使用。我正在Windows 10上对其进行测试。 我能够使用以下命令运行该应用程序: docker pull bkimminich/
我正在尝试使用 NetSuite 中的套件脚本关闭销售订单。 我注意到已经关闭的记录的“状态”设置为“已关闭”。我尝试在提交记录之前设置此字段,但这不起作用,并且记录仍处于“待履行”阶段。 是否还涉及
我是 Thilina,我是 Spring 工具套件的新手。我的操作系统是Windows 8。 我首先提取了“spring-tool-suite-3.1.0.RELEASE-e4.2-win32-x86
我有一个脚本,您可以将测试套件作为参数传递给: $ bash-specs a.suite b.suite 如果用户没有提供任何测试套件,则执行当前文件夹中的所有测试套件。这就是我目前的做法: loca
我目前正在尝试在日志文件中写入 JUnite Suite 失败测试的总数。 我的测试套件定义如下: @RunWith(Suite.class) @SuiteClasses({Class1.class,
我已下载 spring-tool-suite-3.6.1.RELEASE-e4.4-win32-x86_64.zip 并在尝试解压缩和安装时收到以下错误: Error 0x80010135: Path
运行程序test4_4.py时报错,empty test suite. 查找资料发现原因: 默认情况下,pycharm将检查以test开头的文件,它们是unittest.testcase的子类
我是一名优秀的程序员,十分优秀!