PHPUnit:如何为类中的所有测试创建一个要调用一次的函数? [英] PHPUnit: How do I create a function to be called once for all the tests in a class?

查看:48
本文介绍了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() from 第 6 节 PHPUnit 文档.

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:如何为类中的所有测试创建一个要调用一次的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆