php 如何从套件中只运行一个测试?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25074243/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I run only one test from a suite?
提问by Tzook Bar Noy
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');
}
}
回答by Tzook Bar Noy
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.)
(注意套件名和文件名之间的空格。)
回答by Mahmoud Zalt
this is what works:
这是有效的:
codecept run {suite-name} {file-name}.php:{function-name}
codecept 运行 {suite-name} {file-name}.php:{function-name}
notice the space between the suite-name and the file-name
注意套件名和文件名之间的空格
回答by conceptdeluxe
In addition to the answer provided by @Tzook Bar Noyyou can add a trailing $
when there are multiple tests which start with the same name. Consider the following example:
除了@Tzook Bar Noy提供的答案之外,当有多个以相同 name 开头的测试时,您还可以添加尾随$
。考虑以下示例:
<?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$
回答by Akongnwi Devert
A more proper way of doing this will be to assign a group annotation to the test case in question. This is preferable for the following reason; If you have two test cases for example in the same class VisitorCest;
一个更合适的方法是为有问题的测试用例分配一个组注释。由于以下原因,这是优选的;例如,如果您在同一个类 VisitorCest 中有两个测试用例;
public function aboutPage
public function aboutPage2
Executing
执行
codecept run tests/acceptance/VisitorCest.php:aboutPage
will run both VisitorCest:aboutPage and VisitorCest:aboutPage2 test cases.
将同时运行 VisitorCest:aboutPage 和 VisitorCest:aboutPage2 测试用例。
Assign a group to a test case like this
将一个组分配给这样的测试用例
/**
* @group aaa
*/
public function aboutPage(AcceptanceTester $I)
{
}
And execute this particular test case like this
并像这样执行这个特定的测试用例
codecept run -g aaa
codecept run -g aaa
回答by Igor Parra
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
回答by YannҶ
this is what I do.
php codecept.phar run unit UnitNameTest.php
这就是我所做的。
php codecept.phar run unit UnitNameTest.php
回答by Muhammad Shahzad
If you are using PHP Yii2 Framework
, then you can run only one test using this command.
如果您正在使用PHP Yii2 Framework
,那么您只能使用此命令运行一个测试。
Make sure you are in tests directory.
确保您在测试目录中。
cd /codeception/frontend
codecept run -vv acceptance HomeCept
回答by atul_systematix
Try it phpunit --filter {TestMethodName} {FilePath}
试试吧 phpunit --filter {TestMethodName} {FilePath}