DEV Community

loading...

Discussion on: New to front-end testing? Start from the top of the pyramid!

Collapse
frivolta profile image
Filippo Rivolta

Great post! Just a question that I am encountering right now that fits the example in your first video, the signup form. What is the best practice here? Do you use a real dB and you clean it up after every test or you mock a registration? Keep it up!

Collapse
noriste profile image
Stefano Magni Author

Hi Filippo! Speaking only about the E2E tests... there are two approaches that depend on the back-end architecture: are the back-end+DB created just for the sake of the tests/pipeline? Or are they the "staging" (but "common" and so reused) ones?

  • if the BE+DB are created on the fly just for the pipeline you can create the user in advance and then forget to delete them. The disadvantage is that you need to create in advance all the data that you need for every scenario (a new user, a new product, etc. it's called "data seeding")
  • if the BE+DB already exist you can create some entities in advance... but then you need to clear them before every test (on Cypress the "afterEach/afterAll" hooks are not granted to be called based on the success of the tests) and after every test (to avoid finding a lot of garbage data if you manually consume the staging environment). Anyway, you need some dedicated users, with some dedicated data, etc. but this is for E2E testing, usually, you NEED to have some E2E tests because they're the only ones that guarantee you that everything works... but you're going to spend most of your front-end development time with UI Integration tests and everything stubbed 😉but they're different kind of tests that live close to each other
Collapse
frivolta profile image
Filippo Rivolta

Crystal clear, as always! Thanks for your work 😉