Heim  >  Artikel  >  Backend-Entwicklung  >  PHPUnit如何通过注解生成测试类

PHPUnit如何通过注解生成测试类

WBOY
WBOYOriginal
2016-06-06 20:23:091342Durchsuche

我在《PHP核心技术与最佳实践》(列旭松 陈文 著)中的第12章节中了解到PHPUnit可以通过注解生成测试类:

<code>class Calculator
{
    /**
     * @assert (0, 0) == 0
     * @assert (0, 1) == 1
     * @assert (1, 0) == 1
     * @assert (1, 1) == 2
     * @assert (1, 1) == 3
     */
    public function add($a, $b){
        return $a + $b;
    }

    public function add2($a, $b){
        return $a + $b;
    }

}</code>

以上代码会生成五个assert断言,但是书中是使用NetBean,我手头条件限制无法复现,请问如何通过命令完成以上需求?(PHPUnit stable v5.0)

回复内容:

我在《PHP核心技术与最佳实践》(列旭松 陈文 著)中的第12章节中了解到PHPUnit可以通过注解生成测试类:

<code>class Calculator
{
    /**
     * @assert (0, 0) == 0
     * @assert (0, 1) == 1
     * @assert (1, 0) == 1
     * @assert (1, 1) == 2
     * @assert (1, 1) == 3
     */
    public function add($a, $b){
        return $a + $b;
    }

    public function add2($a, $b){
        return $a + $b;
    }

}</code>

以上代码会生成五个assert断言,但是书中是使用NetBean,我手头条件限制无法复现,请问如何通过命令完成以上需求?(PHPUnit stable v5.0)

原来是一个生成骨架来的:第 13 章 骨架(Skeleton)生成器

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn