[PHP] PHPUnit Introduction to the second

Source: Internet
Author: User
Data Providers

A test method can accept any parameter. These parameters can be provided by a data provider method (provider () in the following example).
The data provider method is declared with @dataprovider.
A data provider method must be public, can return a set of arrays, or it can return an object that inherits from the iterator interface and produces an array based on each step iteration.
For each array is part of the collection, and the test method invokes the array contents as its arguments.

Code

1 2 class Datatest extends Phpunit_framework_testcase
3 {
4/* *
5 * @dataProvider Provider
6 */
7 Public Function Testadd ($a, $b, $c)
8 {
Assertequals 9 $this ($c, $a + $b);
10}
11
Public function provider ()
13 {
The return Array (
Array (0, 0, 0),
Array (0, 1, 1),
Array (1, 0, 1),
Array (1, 1, 3)
19);
20}
21}
?>


PHPUnit Datatest
PHPUnit 3.4.2 by Sebastian Bergmann.

... F

time:0 seconds

There was 1 failure:

1) Testadd (datatest) with data (1, 1, 3)
Failed asserting that matches expected value .
/home/sb/datatest.php:21

failures!
Tests:4, Assertions:4, failures:1.
In the above example, the fourth set of data tests did not pass.
* When a test accepts parameters from both the @dataprovider method and one or more @depends methods, the parameters from the data provider will precede the parameters from the @depends.
  • 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.