boraarslan / mapper-influence

0 stars 0 forks source link

Refactor SQLx tests to reduce connection errors #7

Closed boraarslan closed 1 year ago

boraarslan commented 1 year ago

SQLx creates a separate database for each test annotated with #[sqlx::test], and sometimes our test suite fails because SQLx can't connect to the database. Ideally, we want as few tests as possible so we won't get database connection errors when running the tests.

One way to solve this would be merging similar tests into one test. Such as:

#[sqlx::test]
async fn test_insert_user(db: PgPool) { /* ... */ }

#[sqlx::test]
async fn test_insert_no_bio(db: PgPool) { /* ... */ }

#[sqlx::test]
async fn test_insert_same_id(db: PgPool) { /* ... */ }

// These three tests can be merged into one test

#[sqlx::test]
async fn test_insert_user(db: PgPool) { /* We test all of the insert scenarios here */ }