Benjamest's avatar

Can I specify a database connection for an individual unit test?

My test suite currently has 67 tests and 167 assertions. If I run the tests in a SQLite memory database, the tests run in less than 20 seconds. If I run them in MySQL, they take a lot longer, so I'd prefer to run all the tests that I can using the SQLite memory database.

However, I have a table that contains spatial data, and SQLite doesn't support spatial data. I want to run tests on that model and table using the MySQL driver. Can I specify the MySQL database connection for an individual unit test while running the rest in SQLite?

0 likes
6 replies
Benjamest's avatar

That's a shame. I'd hoped that I could use the parent::setup() to set the dB_connection for just that one test suite. I can't find anything that actually works though.

Benjamest's avatar

Yeah, exactly the same issue. I thought it would be easier to copy /paste (my bad!) and that answer doesn't work.

Benjamest's avatar

Bump - does anyone know if this is possible? I'm using Laravel 7

erikwestlund's avatar

I would advise against this. Develop strategies to not run all the tests all the time rather than trying to run your tests in an environment that doesn't match production. You'll get bitten--I have.

Please or to participate in this conversation.