Skip to content

Why are tests marked with #[serial]? #766

Answered by kaplanelad
giovanniberti asked this question in Q&A
Discussion options

You must be logged in to vote

Tests marked with #[serial] are primarily used to prevent interference between tests, especially when they involve shared resources like a database.

For example, when running a test that interacts with a database (such as a controller that creates a user), the following steps might occur:

  • Clear the database.
  • Seed the database with necessary data.
  • Make the request to create a user.
  • Validate the response.
  • Verify the record in the database.

If these steps were run in parallel with other tests, it could lead to conflicts, such as data being overwritten or tests failing unpredictably due to race conditions. By marking the test with #[serial], we ensure that it runs in isolation, preventing o…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@giovanniberti
Comment options

@kaplanelad
Comment options

Answer selected by giovanniberti
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants