Summer Sale! All accounts are 50% off this week.

bor1904's avatar

Few questions about testing

Hello Guys, Im writing code for few years but Im totaly new in testing world. I watched many movies and wrote a lot of text about testing web apps but... in most cases it describes heppy scenarios and easy cases.

  1. Do you use PEST or raw PHPUnit for unit tests? If pest -> why ?
  2. For E2E tests -> Cypress or Dusk? (I see that cypress is veeeery popular but in my opinion Dusk in laravel apps has more posibilities)
  3. How do you organize files/directories structure in laravel "tests" directory?
  4. Do you have performance problems with Dusk when you run over a hundred tests in serie? If yes what is the solution ?
  5. What about migrations+seeds between tests if in my case this process needs about 10min (import data from ext sources and handling photos)?

If somebody can answer only for one or two questions then I will read it with pleasure too :)

thank you K

0 likes
1 reply
tisuchi's avatar

@bor1904

Do you use PEST or raw PHPUnit for unit tests? If pest -> why ?

Answer: I personally prefer to use PHPUnit because it's one of the most popular uses frameworks.

For E2E tests -> Cypress or Dusk? (I see that cypress is veeeery popular but in my opinion Dusk in

laravel apps has more posibilities)

Answer: As you correctly mentioned, for laravel project, I give priority to Dusk over Cypress.

How do you organize files/directories structure in laravel "tests" directory?

Answer: I prefer to follow the same app structure in the test directory.

For example-

Here is my app structure

- App\
	- Controllers\
		- Api
		- Web

Here is my Test directory-

- tests\
	- Unit
		- Controllers
			- Api
				- Put all Api related controllers here
			- Web 
				- Put all Web related Controllers here

Do you have performance problems with Dusk when you run over a hundred tests in serie? If yes what is the solution ?

Answer: You can make grouping your test. Sometimes, you may not need to run 100+ tests at a time. It will be way easier to group them and then run a specific group when you need. Check more: https://laravel.com/docs/8.x/dusk#running-tests

However, to run all tests, you may optimize your tests. For example, in some tests, you may not need any DB connection. In that case, you just remove DB integration from that test to make it a bit faster.

What about migrations+seeds between tests if in my case this process needs about 10min (import data from ext sources and handling photos)?

Answer: I am not sure how much data you are dealing with. Normally I try to use a bash script to run my application. And my personal preference is to seed all data during booting up the application.

However, the main reason for testing data is to make sure that the application is behaving as expected. In that case, you can deal with a minimal amount of data that will run your testing faster.

1 like

Please or to participate in this conversation.