beyondcode / dusk-dashboard

A beautiful dashboard for your Laravel Dusk tests
https://pociot.dev/8-introducing-laravel-dusk-dashboard
MIT License
558 stars 62 forks source link

"This test did not perform any assertions" error #30

Closed vesper8 closed 8 months ago

vesper8 commented 5 years ago

So I've been banging my head as to why suddenly my tests don't work anymore, and then I remembered I installed this package but haven't been using it. I reverted this line to the default and now everything works again

use BeyondCode\DuskDashboard\Testing\TestCase as BaseTestCase;

back to

use Laravel\Dusk\TestCase as BaseTestCase;

Keep in mind I wasn't running the dashboard at all, just trying to run my tests from the command line as per usual

I was getting this error:

This test did not perform any assertions

And the test was judged to be "risky"

It's probably because of my unconventional way of testing.. let me explain what I do in my app so you might understand why it isn't working.

I have one single test which loads some parameters from the cache (which are set as part of another console method with Cache::forever

This one single test calls a Page and passes it those things loaded from the cache, and the page then uses those params to call a dynamic function. Finally inside that function is where all the assertions are done

Something as simple as this:

PostRecipeTest.php

<?php

namespace Tests\Browser;

use Tests\DuskTestCase;
use Tests\Browser\Pages\PostNewRecipe;

class PostRecipeTest extends DuskTestCase
{
    public function testPostRecipe()
    {
        $site = cache()->get('site');
        $recipe = cache()->get('recipe');

        $this->browse(function ($browser) use ($site, $recipe) {
            $browser->visit(new PostNewRecipe($site, $recipe));
        });
    }
}
<?php

namespace Tests\Browser\Pages;

use Laravel\Dusk\Browser;
use Illuminate\Support\Facades\URL;

class PostNewRecipe extends Page
{
    use SiteScripts;

    protected $site;
    protected $recipe;

    public function __construct($site, $recipe)
    {
        $this->site = $site;
        $this->recipe = $recipe;
    }

    public function url()
    {
        return $this->site['login_path'];
    }

    /**
     * Assert that the browser is on the page.
     *
     * @return void
     */
    public function assert(Browser $browser)
    {
        $functionName = $this->site['name'];

        return $this->$functionName($browser);
    }

Inside the method called above

    public function someMethod(Browser $browser)
    {
        $browser->resize(1024, 768); // Width and Height

        $browser->assertPathIs('/');
        ...

When using

use BeyondCode\DuskDashboard\Testing\TestCase as BaseTestCase;

The test would always reach this first assertion (assertPathIs) and would exit there, not giving a failure but rather exiting with the error 'This test did not perform any assertions'

I guess this package does not like the way I'm testing my assertions into a method instead of being directly included in the Page's assert() method.. do you have any idea why? Works perfectly with vanilla Laravel Dusk

Regards

kyranb commented 5 years ago

Having the exact same error.

kerimkuscu commented 5 years ago

Having the exact same error. All test is passed. But i don't seen any action in dusk dashboard. Im using use Laravel\Dusk\TestCase as BaseTestCase;

TivoSoho commented 5 years ago

I had the same issue and after puzzling over it for a couple of days I finally figured out my problem.

Dusk dashboard suppresses errors.

I had a problem where in some cases I did not pass on a message to my custom PHPUnit assertion - it was null when it needed to be an empty string. It should have resulted in an error. Dusk dashboard however simply returned from that browse closure and continued on testing like there was nothing wrong. In one case it probably should have failed before since I was testing for something that had findOrFail and it did not fail.

I really liked the thought of having the option to run the tests in browser when it claimed to not find an element that I saw was right there on the screenshot. But mostly I run them command line. And while catching exceptions may work in browser mode - in command line mode Dusk dashboard is dangerous for the error suppression. It also does NOT report findOrFail errors, which should be thrown as exceptions per source code, if I remember correctly.

I personally have not found much use for the Dashboard as I cannot limit the tests being run by the browser. We are trying to cover our entire application by tests and mostly the dashboard just dies after running for a while. So uninstall for me.

dbierer commented 1 year ago

I ran into a similar problem today on PHPUnit 10.2.2 with a PHP 8.1.4 installation. Turns out there were SQL errors and a few other errors which were not showing up. When I fixed the errors, the "This test did not perform any assertions" message went away and the test ran OK.