laravel 在 phpunit 中运行一个文件或地图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35596637/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:17:43  来源:igfitidea点击:

Run one file or map in phpunit

phplaravelphpunit

提问by Jamie

I'm using laravel and I've written some test files. But how can I exec only one file? When I do for example: phpunit tests/resulttesting/school/deleteSchoolForRealTestIt throws an error:

我正在使用 laravel 并编写了一些测试文件。但是我怎么能只执行一个文件呢?例如,当我这样做时:phpunit tests/resulttesting/school/deleteSchoolForRealTest它会引发错误:

Cannot open file "tests/resulttesting/school/deleteSchoolForRealTest.php".

无法打开文件“tests/resulttesting/school/deleteSchoolForRealTest.php”。

When I run phpunit it runs all my tests. And how can I exec only one folder? I'm on a mac.

当我运行 phpunit 时,它会运行我所有的测试。我怎样才能只执行一个文件夹?我在 mac 上。

回答by Yevgeniy Afanasyev

You are doing everything correctly.

你做的一切都是正确的。

1) First way to add folder. My correct way was:

1)第一种添加文件夹的方法。我的正确做法是:

phpunit tests/EWalletTest

I had same errors when I forget to start from "tests" folder

当我忘记从“tests”文件夹开始时,我遇到了同样的错误

phpunit EWalletTest

I got

我有

Cannot open file "EWalletTest.php".

无法打开文件“EWalletTest.php”。

2) Filteris another option. read hereexample:

2)过滤器是另一种选择。在这里阅读示例:

phpunit --filter EWallet

Only runs tests whose name matches the given regular expression pattern.

仅运行名称与给定正则表达式模式匹配的测试。

Meaning that you will have executed files EWalletTestand EWalletFooTestand test cases from other filee with names like `test_EWallet_with_Australian_dollar.

这意味着您将执行来自其他文件的文件EWalletTestEWalletFooTest测试用例,名称类似于“test_EWallet_with_Australian_dollar”。

回答by Mohammed Radwan

Use filter option

使用过滤器选项

phpunit --filter=EWalletTest

回答by f_i

Using phpunit.xml

使用 phpunit.xml

the @groupoption can be used on classes and methods.

@group选项可用于类和方法。

class A

A级

/**
 * @group active
 * */
class ArrayShiftRightTest extends TestCase
{
}

class B

B级

/**
 * @group inactive
 * */
class BinaryGapTest extends TestCase
{    
}

in phpunit.xml

在 phpunit.xml 中

<groups>
    <include>
        <group>active</group>
    </include>
    <exclude>
        <group>inactive</group>
    </exclude>
</groups>

the classes that belongs to group active will be executed.

将执行属于组 active 的类。