如何才能在一个套件中只运行一个测试?

时间:2021-11-29 20:28:04

I have this test class below, and I want to run only one test from it, for example the "aboutPage". Any ideas how?

我在下面有一个测试类,我只希望从中运行一个测试,例如“aboutPage”。任何想法如何?

This is how I run only this file:

我就是这样运行这个文件的:

codecept run tests/acceptance/VisitorCest.php

But now I want to run only one test from the file.

但是现在我只想从文件中运行一个测试。

<?php
use \AcceptanceTester;

class VisitorCest
{
    public function _before(){}
    public function _after(){}

    public function aboutPage(AcceptanceTester $I)
    {
        $I->wantTo('check about page');
    }

    public function contactPage(AcceptanceTester $I)
    { 
        $I->wantTo('check contact page');
    }
}

7 个解决方案

#1


97  

You simply append a colon and the function name, like this:

只需添加一个冒号和函数名,如下所示:

codecept run tests/acceptance/VisitorCest.php:myTestName

or a shorter version:

或更短的版本:

codecept run acceptance VisitorCest:myTestName

(Notice the space between the suite-name and the file-name.)

(请注意求助者名称和文件名称之间的空格。)

#2


29  

this is what works:

这就是工作原理:

codecept run {suite-name} {file-name}.php:{function-name}

codecept {套件名} {文件名}。php运行:{函数名称}

notice the space between the suite-name and the file-name

请注意求助者名称和文件名称之间的空格

#3


10  

In addition to the answer provided by @Tzook Bar Noy you can add a trailing $ when there are multiple tests which start with the same name. Consider the following example:

除了@Tzook Bar Noy提供的答案之外,当有多个以相同名称开头的测试时,还可以添加一个尾随$。考虑下面的例子:

<?php

use \AcceptanceTester;

class VisitorCest
{
    public function aboutPage(AcceptanceTester $I)
    {
    }

    public function aboutPageOption(AcceptanceTester $I)
    { 
    }
}

Where the following command will execute both of the tests:

以下命令将执行这两个测试:

codecept run tests/acceptance/VisitorCest.php:aboutPage

This will execute only the first:

这将只执行第一个:

codecept run tests/acceptance/VisitorCest.php:aboutPage$

#4


2  

In addition to the previous answers, you can run one or several methods by grouping by a given name:

除了前面的答案之外,您还可以通过一个给定名称分组运行一个或多个方法:

/**
 * @group test-aboutPage
 */
public function aboutPage(AcceptanceTester $I)
{
    $I->wantTo('check about page');
}

Use the option -g and the name of the group:

使用选项-g和组名:

$ codecept run acceptance VisitorCest -g test-aboutPage

#5


1  

this is what I do. php codecept.phar run unit UnitNameTest.php

这就是我所做的。php codecept。phar运行单元UnitNameTest.php

#6


0  

If you are using PHP Yii2 Framework, then you can run only one test using this command.

如果您使用的是PHP Yii2框架,那么您只能使用这个命令运行一个测试。

Make sure you are in tests directory.

确保您在测试目录中。

cd /codeception/frontend

codecept run -vv acceptance HomeCept

#7


-1  

Try it phpunit --filter {TestMethodName} {FilePath}

试试phpunit——filter {TestMethodName} {FilePath}

#1


97  

You simply append a colon and the function name, like this:

只需添加一个冒号和函数名,如下所示:

codecept run tests/acceptance/VisitorCest.php:myTestName

or a shorter version:

或更短的版本:

codecept run acceptance VisitorCest:myTestName

(Notice the space between the suite-name and the file-name.)

(请注意求助者名称和文件名称之间的空格。)

#2


29  

this is what works:

这就是工作原理:

codecept run {suite-name} {file-name}.php:{function-name}

codecept {套件名} {文件名}。php运行:{函数名称}

notice the space between the suite-name and the file-name

请注意求助者名称和文件名称之间的空格

#3


10  

In addition to the answer provided by @Tzook Bar Noy you can add a trailing $ when there are multiple tests which start with the same name. Consider the following example:

除了@Tzook Bar Noy提供的答案之外,当有多个以相同名称开头的测试时,还可以添加一个尾随$。考虑下面的例子:

<?php

use \AcceptanceTester;

class VisitorCest
{
    public function aboutPage(AcceptanceTester $I)
    {
    }

    public function aboutPageOption(AcceptanceTester $I)
    { 
    }
}

Where the following command will execute both of the tests:

以下命令将执行这两个测试:

codecept run tests/acceptance/VisitorCest.php:aboutPage

This will execute only the first:

这将只执行第一个:

codecept run tests/acceptance/VisitorCest.php:aboutPage$

#4


2  

In addition to the previous answers, you can run one or several methods by grouping by a given name:

除了前面的答案之外,您还可以通过一个给定名称分组运行一个或多个方法:

/**
 * @group test-aboutPage
 */
public function aboutPage(AcceptanceTester $I)
{
    $I->wantTo('check about page');
}

Use the option -g and the name of the group:

使用选项-g和组名:

$ codecept run acceptance VisitorCest -g test-aboutPage

#5


1  

this is what I do. php codecept.phar run unit UnitNameTest.php

这就是我所做的。php codecept。phar运行单元UnitNameTest.php

#6


0  

If you are using PHP Yii2 Framework, then you can run only one test using this command.

如果您使用的是PHP Yii2框架,那么您只能使用这个命令运行一个测试。

Make sure you are in tests directory.

确保您在测试目录中。

cd /codeception/frontend

codecept run -vv acceptance HomeCept

#7


-1  

Try it phpunit --filter {TestMethodName} {FilePath}

试试phpunit——filter {TestMethodName} {FilePath}