Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

264
Visualizações
How to handle test data for e2e tests?

I have a node app connecting to a MySQL database that I want to write end to end tests for.

This means I need some test data in the database but I don't want tests from ./test-1.test.js to effect tests in ./test-2.test.js.

For example my first test deletes a record:

test-1.test.js

it('Should delete record', async () => {
  await supertest(server)
    .delete(`/record/id_1`)
    .expect(OK, expectedData);
})

and then have my second test try to consume the record that was deleted in the previous test

it('Should retrieve record', async () => {
  await supertest(server)
    .get(`/record/id_1`)
    .expect(OK, expectedData);
})

Potential solutions:

  1. I was considering either running a seed before I start my test. This would require a lot of variations of data and would not be clear as to what data is being used by what tests, potentially leading to flakey and unreliable tests if the order of tests gets moved around or one test file is run before the other.

  2. Populate the data in a beforeEach or beforeAll block using my models. i.e.


beforeEach(async () => {
  await MyModel.create(myTestData)
});

afterEach(async () => {
  await MyModel.drop() // drops table - would need to run migrations before I run the next test
});

it('Should retrieve record', async () => {
  await supertest(server)
    .get(`/record/id_1`)
    .expect(OK, expectedData);
});

If I drop a table after each or all tests, is there a way to then re run my migration so that the table is pushed back into the schema? Rather than dropping the table, am I best to just delete the record specifically? Seems like this is creating a lot of logic in my tests though.

I'm open to suggestions. Keen to hear how you handle your test data / seeds in your e2e tests too

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda