Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jeFFF's avatar
Level 3

Testing takes a lot of time on debian 12

Hello there,

I have a very annoying issue with pest / phpunit on my machine and I can't find a solution My setup is a Dell with 64GB ram and SSD and my OS is Linux Mint LMDE 6 (based on debian 12). I develop a project with Laravel 11 and my development environment is Sail with MySql server 8 and PHP 8.4.

When I launch tests it takes 6-10 seconds to launch the first one, and for the others PHP some are very quick (0.2s) but when I create Factories, some of them go to 1.2 to 1.7s. With 251 assertions already it takes nearly a minute to execute all of them

Tests:    4 failed, 7 todos, 129 passed (251 assertions)
 Duration: 56.64s

I tried to run all the tests with --parralel it's a bit better but very slow as well :

Tests:    4 failed, 7 todos, 129 passed (251 assertions)
  Duration: 42.90s
  Parallel: 12 processes

Except from tests, the app is running perfectly and response times are very quick. Seeding is quick as well.

Does some one on full linux systems had same issues ? Is there a way to make this quicker ? I'm very puzzled with this issue.

0 likes
4 replies
LaryAI's avatar
Level 58

To address the issue of slow test execution times in your Laravel project on a Debian-based system, there are several strategies you can employ to potentially improve performance:

  1. Optimize Database Configuration:

    • Ensure that your MySQL server is configured for optimal performance. You can adjust settings like innodb_buffer_pool_size, query_cache_size, and max_connections in your MySQL configuration file (my.cnf or my.ini).
  2. Use In-Memory Database for Testing:

    • Consider using an in-memory database like SQLite for your tests. This can significantly speed up test execution since it eliminates the overhead of disk I/O.
    • Update your phpunit.xml or pest.php configuration to use SQLite:
      <env name="DB_CONNECTION" value="sqlite"/>
      <env name="DB_DATABASE" value=":memory:"/>
      
  3. Optimize Test Setup:

    • Ensure that your test setup is efficient. Avoid unnecessary database seeding or setup operations that can be done once in a setUpBeforeClass method instead of setUp.
  4. Use Factories Efficiently:

    • If your tests rely heavily on factories, ensure that they are not creating more data than necessary. Use make instead of create when you don't need to persist data to the database.
  5. Profile and Optimize Tests:

    • Use tools like Laravel Telescope or Xdebug to profile your tests and identify bottlenecks. Focus on optimizing the slowest tests first.
  6. Parallel Testing:

    • While you mentioned using --parallel, ensure that your tests are truly parallelizable. Some tests might have dependencies that prevent them from running concurrently.
  7. Upgrade Hardware Resources:

    • Although your machine seems well-equipped, ensure that Docker (used by Sail) is allocated sufficient resources (CPU, memory) to run efficiently.
  8. Check for External Factors:

    • Ensure that no other processes are consuming significant resources on your machine during test execution.

By implementing these strategies, you should be able to reduce the time it takes to run your test suite. If the problem persists, consider isolating specific tests to identify any particular ones that are causing delays.

dumitru-caldare's avatar
Level 18
  • You mentioned that you run the application with sail, so the first thing I would do is check how much resources are allocated for you docker container
  • The second thing I would add the DatabaseTransactions trait, so this way you will run the migration for the test database one time and each test will be executed inside a mysql transaction, that will be rolled back after the execution
  • The last thing is to check the code line by line and see what can be improved
1 like
jeFFF's avatar
Level 3

@dimka7 OMG ! thanks for that !

-> the ressources seems enough as the migration process and my app runs smoothly, my issue was only for testing

-> the DatabaseTransactions speeded up the tests, I still have slow ones but i will investigate them

-> cf. the previous point ;)

Anyway, I gained more than 10 seconds on normal execution (I haven't investigate yet), more important I gained 40s using parallel which is a great improvment !

1 like
jeFFF's avatar
Level 3

@dimka7 Thanks again, with a few optimisations for point 2, my tests are now taking 11s and 4s using --parallel

1 like

Please or to participate in this conversation.