0

I have my own Laravel package and I want to be able to write and create tests for it.

My project is installed on the following directory within my project ROOT/CompayName/package-name. My tests are located in ROOT/CompanyName/package-name/tests while the code is located in ROOT/CompanyName/package-name/src.

In the composer.json file I autoload my tests like this

"autoload-dev": {
    "psr-4": {
        "Tests\\": "tests/",
        "CompayName\\ProjectName\\": "CompayName/package-name/tests/"
    }
},

Additionally, I added the following to the phpunit.xml file

<testsuite name="Unit">
    <directory suffix="Test.php">./tests/Unit</directory>
    <directory suffix="Test.php">./CompanyName/project-name/tests/</directory>
</testsuite>

Then I create the following test

<?php

namespace CompanyName\ProjectName;

use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;

class SomeKindOfTest extends TestCase
{
    /**
     * A basic test example.
     *
     * @return void
     */
    public function ableToDoSomething()
    {       
        dd('ableToDoSomething was called!!!!!!!!!!!');
    }
}

However, when I run phpunit from the command line, my test isn't being fired!

How can I correctly fire the tests in my package.

Junior
  • 11,602
  • 27
  • 106
  • 212

1 Answers1

0

PHPUnit usually runs the methods named test*, unless you have specified otherwise in phpunit.xml.

Try renaming your test:

public function testAbleToDoSomething() {}

PHPUnit also supports a special /** @test */ annotation inside the docblock:

/** @test */
public function ableToDoSomething() {}
Travis Britz
  • 5,094
  • 2
  • 20
  • 35
  • Thank you for the info. I tried renaming the method to start with the keyword `test` and I also tried to decorate it with the `/** @test */` but still now working. – Junior Mar 16 '19 at 23:21