PHPUnit: How do I create a function to be called once for all the tests in a class?(PHPUnit:如何为类中的所有测试创建一次调用的函数?)
问题描述
我有一个 PHPUnit 测试用例类(由一些测试函数组成).我想为类中的所有测试编写一个 oneTimeSetUp() 函数(与每个测试调用一次的标准
setUp()
函数不同在课堂里).换句话说,我正在寻找与 JUnit @BeforeClass
等效的 PHPUnit注释.
I have a PHPUnit test case class (consisting of some test functions). I would like to write a oneTimeSetUp()
function to be called once for all my tests in the class (unlike the standard setUp()
function which is called once for each test in the class). In other words, I'm looking for a PHPUnit equivalent to the JUnit @BeforeClass
annotation.
与 oneTimeTearDown()
函数相同的问题.
Same question with a oneTimeTearDown()
function.
在 PHPUnit 中可以这样做吗?
Is it possible to do so in PHPUnit?
推荐答案
看看 setUpBeforeClass()/fixtures.html#fixtures.more-setup-than-teardown" rel="noreferrer">PHPUnit 文档的第 6 节.
Take a look at setUpBeforeClass()
from section 6 of the PHPUnit documentation.
一次性tearDown你应该使用tearDownAfterClass();
.
For the one time tearDown you should use tearDownAfterClass();
.
这两种方法都应该在您的类中定义为静态方法.
Both this methods should be defined in your class as static methods.
这篇关于PHPUnit:如何为类中的所有测试创建一次调用的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHPUnit:如何为类中的所有测试创建一次调用的函数?


基础教程推荐
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何替换eregi() 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01