DEV Community


Discussion on: How to test views?

grahamcox82 profile image
Graham Cox Author

So, I'm actually doing three levels of testing:

  • Unit Testing of the individual pieces of code
  • "Integration Testing" of the service. On this one I am calling the controllers directly, and asserting that the rendered view is the correct HTML. I am not doing any workflows here though - each test is one controller and one assert.
  • End-To-End Testing of the service. On this one I am using Selenium to drive the application in a real browser, and ensuring that flows between pages work correctly.

I'm very happy with the Unit and End-to-End tests, but less so on the Integration tests.

I fully get where you're coming from on the selectors to pick out appropriate pieces of the page. However, I'm concerned that might miss things. For example, my "User Profile" page I could easily pick out the "Username" and "Email" fields and ensure they are populated correctly. But should I also pick out the "User menu" in the header bar and make sure that's correct? If so, do I do that on every page since it's rendered on every view? And if now then when do I test that, since it might feasibly be broken on only one view.

Conversely, my current approach of snapshot testing ensures that the header is tested on every view, and implicitly tests that every part of the page is as expected. But it's brittle to page-wide changes. If I change the header then every single snapshot is not invalid.

Forem Open with the Forem app