PHPUnit: How to create a function to be called once for all the tests in a class

PHPphpunit

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.

Same question with a oneTimeTearDown() function.

Is it possible to do so in PHPUnit?

Best Answer

Take a look at setUpBeforeClass() from section 6 of the PHPUnit documentation.

For the one time tearDown you should use tearDownAfterClass();.

Both this methods should be defined in your class as static methods.

Related Topic