I was starting to write unit tests for my razor pages ( Check out this link ). I was wondering, if I wanted to test whether a link exists for a particular page, I could parse the html and test whether the route “Admin/Index” appears on the page. But what if I change the controller method from Index to Home – it would break my gui unit tests.
Is there a way to unit test whether a link appears on a page that’s not coupled to the controllers?
Thanks!
I don’t think that you should try to abstract your unit tests from the concrete action of your controller. If you change from Index to Home – from the human perspective that’s OK, but from the unit tests perspective it can be DeleteWholeSite instead of Home. And publishing of this link is very dangerous, but can be done by mistake.
So if you change some links on the page, then you should maintain you unit tests, to be sure that your pages contains links reflecting functionality you want provide to the user.