1

I'm trying to test my app using phpunit with laravel but each time I run

unit test

vendor\bin\phpunit

All tables in my database drop so I have to migrate each time I run a test

Have you encountered with similar issue & how can I fix it ?

1 Answer 1

1

Use a separate connection for tests. Add this connection to config/database.php config file:

'connections' => [

    'testing' => [
        'driver' => 'sqlite',
        'database' => ':memory:',
        'prefix' => '',
    ],
Sign up to request clarification or add additional context in comments.

4 Comments

I will try it, but can I use my default database since I'm not in production environment?
I don't recommend using the default database for testing.
@user3763103 why do you want to do that? I agree with Camilo, you should use in-memory database for testing.
Because I'm building the app in a local environment once I done I will move it to the server therefor I thought that I don't need two databases. Anyway it worked Thank you very much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.