22
votes

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/deleteSchoolForRealTest It throws an error:

Cannot open file "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.

3
Make sure you got letter casing right, it depends on your filesystem and the path might be case sensitive. - Jakub Zalas

3 Answers

38
votes

You are doing everything correctly.

1)

First way to add folder. My correct way was:

phpunit tests/EWalletTest

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

phpunit EWalletTest

I got

Cannot open file "EWalletTest.php".

2)

Filter is another option. read here example:

phpunit --filter EWallet

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

Meaning that you will have executed files EWalletTest and EWalletFooTest and test cases from other file with names like `test_EWallet_with_Australian_dollar.

11
votes

Use filter option

phpunit --filter=EWalletTest
0
votes

Using phpunit.xml

the @group option can be used on classes and methods.

class A

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

class B

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

in phpunit.xml

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

the classes that belongs to group active will be executed.