学习phpunit(二)

时间:2020-07-11
本文章向大家介绍学习phpunit(二),主要包括学习phpunit(二)使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1、我的疑问:什么是测试套件

测试套件,是一套业务逻辑验证时,所需要的测试用例,包含测试逻辑、测试预期、测试结果。

一个套件里面,由多个测试类集合,一个测试类中可以有多个测试实例,因此可以测试多个测试类的多个逻辑

2、开始看phpnuit

phpunit 的五个基础类和接口

(1)class TestSuite 实现了(3)Test接口
(2)abstract class TestCase 实现了Test接口,且继承了(4)Assert类
(5)class TestResult 是一个针对期望值做检查的一套方法。
再学习一下,这些类的特点:
Test:所有测试类必须要实现的接口,里面只定义了一个
public function run(TestResult $result = null);一个接口的方法。
TestCase:它的源码,如何构造一个TestCase中,举例是
* <?php
* class MathTest extends PHPUnit\Framework\TestCase
* {
* public $value1;
* public $value2;
*
* protected function setUp()
* {
* $this->value1 = 2;
* $this->value2 = 3;
* }
* }

从类名看,这是一个单元测试(测方法的)的基类(暂时不学,所以不看了)

TestSuite:
/**
     * Constructs a new TestSuite:
     *
     *   - PHPUnit\Framework\TestSuite() constructs an empty TestSuite.
     *
     *   - PHPUnit\Framework\TestSuite(ReflectionClass) constructs a
     *     TestSuite from the given class.
     *
     *   - PHPUnit\Framework\TestSuite(ReflectionClass, String)
     *     constructs a TestSuite from the given class with the given
     *     name.
     *
     *   - PHPUnit\Framework\TestSuite(String) either constructs a
     *     TestSuite from the given class (if the passed string is the
     *     name of an existing class) or constructs an empty TestSuite
     *     with the given name.
*/

从注释看,传入的参数是个类,那么,测试的对象很可能是接口之类的或者一套被测方法,而接口测试其实是一串测试方法的测试(所以,这个是接口测试要学的吧)


TestResult:前面说了,是一串检查期望的比如断言、跳过啊、之类的方法。

原文地址:https://www.cnblogs.com/ansonwan/p/13285302.html