Jump to content


Difference between setUp() and setUpBeforeClass() for unit tests

phpunit unit tests tests

  • Please log in to reply
No replies to this topic

#1 Ivica


    Advanced Member

  • Moderators
  • 565 posts

Posted 27 January 2012 - 12:47 PM

I think it would be useful to mention difference between setUp() and setUpBeforeClass() methods whose can be found in most unit tests we are using.

setUpBeforeClass() method is executed only once per class, and even before object is constructed, and that is reason why it is marked as static public function.
setUp() method is called before every test case, which mean that this method can be called few times per one test class.

Similar is difference between tearDownAfterClass and tearDown(), tearDown() method is called after each test case, and tearDownAfterClass() method is called after all tests in class finish, and after last tearDown() method is called.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users