zoukankan      html  css  js  c++  java
  • PHPUnitWriting Tests for PHPUnit

    The basic conventions and steps for writing tests with PHPUnit:

    1. The tests for a class Class go into a class ClassTest.

    2. ClassTest inherits (most of the time) from PHPUnit_Framework_TestCase.

    3. The tests are public methods that are named test*.

      Alternatively, you can use the @test annotation in a method's docblock to mark it as a test method.

    4. Inside the test methods, assertion methods such as assertEquals() are used to assert that an actual value matches an expected value.

    <?php
    class StackTest extends PHPUnit_Framework_TestCase
    {
        public function testPushAndPop()
        {
            $stack = array();
            $this->assertEquals(0, count($stack));
     
            array_push($stack, 'foo');
            $this->assertEquals('foo', $stack[count($stack)-1]);
            $this->assertEquals(1, count($stack));
     
            $this->assertEquals('foo', array_pop($stack));
            $this->assertEquals(0, count($stack));
        }
    }
    ?>
    

     Whenever you are tempted to type something into a print statement or a debugger expression, write it as a test instead.

  • 相关阅读:
    机器学习概要
    Latex公式压缩
    MATLAB多项式运算
    利用MathType为公式编号并引用
    MATLAB符号对象与符号运算
    MATLAB矩阵运算
    MATLAB绘制函数图
    MATLAB程序控制语句
    MATLAB关系运算符和逻辑运算符
    Raspberry pi之wifi设置-3
  • 原文地址:https://www.cnblogs.com/Hebe/p/3099675.html
Copyright © 2011-2022 走看看