PHP Tutorial: PHPUnit Study Notes (vi) Fixture

Source: Internet
Author: User

The most time to write a test case is to write code that sets the program back to its original state after it has been set up and tested. PHPUnit provided us with the setup and Teardown methods to solve this problem.

Setup is called before each test case of the class is run, and you can do some of the related program initialization work in it.

The Teardown method is called after each test case has finished running, and you can do some cleanup work in it.

It is important to note that the setup is not necessarily written in the Teardown,teardown to be used to reclaim those objects that occupy a large amount of resources, such as the connection of the database, open files and so on. is a simple example of a demo Setup method (click to enlarge)

In addition to setup and teardown, PHPUnit provides some ways to get you ready for more work, see (click to enlarge)

The result of the above test execution
PHPUnit Templatemethodstest
PHPUnit 3.5.13 by Sebastian Bergmann.

Templatemethodstest::setupbeforeclass
Templatemethodstest::setup
Templatemethodstest::assertpreconditions
Templatemethodstest::testone
Templatemethodstest::assertpostconditions
Templatemethodstest::teardown
. Templatemethodstest::setup
Templatemethodstest::assertpreconditions
Templatemethodstest::testtwo
Templatemethodstest::teardown
Templatemethodstest::onnotsuccessfultest
Ftemplatemethodstest::teardownafterclass


time:0 seconds

There was 1 failure:

1) templatemethodstest::testtwo
Failed asserting <boolean:false> is true.
/home/sb/templatemethodstest.php:30

failures!
Tests:2, Assertions:2, failures:1.

PHP Tutorial: PHPUnit Study Notes (vi) Fixture

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.