OgreKing's avatar

Trait "JMac\Testing\Traits\AdditionalAssertions" not found

Hello, I have a fresh Laravel 11 app. I am using Laravel Shift:Blueprint to scaffold my models, controllers and tests... They recommend jasonmccreary/laravel-test-assertions for the tests (PHPUNIT) they generate.

When I run php artisan test and my tests trigger I get this error: Fatal error: Trait "JMac\Testing\Traits\AdditionalAssertions" not found . I am not sure why the name space isn't working. Any tips?

0 likes
2 replies
LaryAI's avatar
Level 58

It sounds like you're encountering an issue with a missing trait from the jasonmccreary/laravel-test-assertions package. Here are the steps to resolve this issue:

  1. Ensure the Package is Installed: First, make sure that the jasonmccreary/laravel-test-assertions package is actually installed in your project. You can do this by running:

    composer require jasonmccreary/laravel-test-assertions --dev
    

    This command installs the package and ensures it's only included in your development environment.

  2. Check the Namespace: Verify that the namespace used in your test files matches the namespace provided by the package. It seems like there might be a typo or an outdated reference in your tests.

  3. Update Your Test File: In your test file, make sure you are using the correct namespace and trait. Here's how you might include it:

    use JMac\Testing\Traits\AdditionalAssertions;
    
    class YourTest extends TestCase
    {
        use AdditionalAssertions;
    
        // Your test methods here
    }
    
  4. Autoload Dump: Sometimes, the composer autoload files might be out of sync, especially after adding new packages. Run the following command to regenerate the autoload files:

    composer dump-autoload
    
  5. Run Your Tests Again: After making these changes, try running your tests again:

    php artisan test
    

If you follow these steps and still face issues, double-check the documentation for the jasonmccreary/laravel-test-assertions package to ensure there haven't been any changes or deprecations related to the AdditionalAssertions trait that you might have missed.

1 like
jadwer's avatar

I had the same error, just change

use JMac\Testing\Traits\AdditionalAssertions;

to

use JMac\Testing\Traits\HttpTestAssertions;

in all your test files.

Please or to participate in this conversation.