8

I have an angular application that relies on a dotnet core web api, and I'd like to write e2e tests that exercise CRUD actions on various resources and verify that the angular app responds appropriately responses/events implemented in the API. I recognize that in a lot of cases, one would want to mock the back-end because the e2e tests in angular are normally supposed to limit their concern with making sure the front-end behaves accordingly, not that the separate front-end and back-end applications behave appropriately together. But that's exactly what I want to do.

Question

Is there a common way to get front-end e2e test runs to rely on local instantiations of the back-end application that can also restore database snapshots? Further, when considering continuous integration, would you still rely on "local" instantiations of the back-end application on the CI machine, or would you point it to an already running testing server? Also, an alternative I started considering was to introduce an endpoint in the API itself that could restore database snapshots that my angular e2e tests invoke at the end of each test, in like a afterEach(...), for example.

I've also considered using an in-memory db or just mocking the backend, but that backend inherently lacks the specific behavior implemented in the web api, and it seems like mocking that behavior is just implementing that behavior twice.

What have you or others done to solve this?

Jake Smith
  • 2,332
  • 1
  • 30
  • 68
  • For my teams Protractor E2E tests we run the tests locally against our Angular front ends and our rest apps. We use the database that is being developed against, because it would be a lot more difficult to run the sql on our test environment. I think restoring a database snapshot through angular could be difficult and cause a lot of inconsistencies. I know that a Restful app is different, but I thought I'd put my 2 cents in. – Brett Holmes Mar 29 '18 at 17:30
  • 1
    @PhotographyBum Thanks for your response! So, does your e2e tests handle cleanup then? Or do your tests run in a particular order and rely on each other? What I'm worried about is test failures cascading down the rest of the test suite because of tests depending on one another to succeed. – Jake Smith Mar 29 '18 at 17:44
  • 2
    Yes, we have a `beforeAll()` that will create a user, post data to our Rest app to create the data but not test our Admin side (which we're not testing when we test our User app to speed up the process), test the User app, and then use an `afterAll()` that deletes the data we posted to clean it all up. – Brett Holmes Mar 29 '18 at 17:56
  • @PhotographyBum, so does your `afterAll` have to check whether a potentially failed test actually made the changes it was supposed to before trying to clean up? Or does it just make the call to cleanup regardless of previous test failures? – Jake Smith Mar 29 '18 at 18:51
  • 2
    Sorry for the late response, No it does not, because the `beforeAll()` is in the spec.js, but not in a "test". This allows for the data to be inserted, tests to be ran (not creating new data luckily), and then cleaning up the inserted data. The only problem we've faced is if the api sends back an error when we're inserting the data, then most of our tests will fail and the data cleanup will error out, but then that just means something needs to be fixed on the rest side. – Brett Holmes Apr 02 '18 at 11:36

0 Answers0