We use automated tests to verify functionality of our web application. In order to make assertions in test cases less complicated and more flexible, we are considering the introduction of 'TestIDs', i.e. IDs in the HTML markup that help testcases find and verify elements on the page. Additionally, these TestIDs would allow more specific integration tests which are currently impossible due to the limited data on the pages.
However, here is what makes us hesitate:
Limiting TestIDs to test/staging HTML doesn't seem to be a good idea because we obviously want to test code that will be used in production and don't want our test/staging environment to behave differently. In fact, we currently run parts of our test suites against the live system after a release.
Do you think TestIDs are a good idea and if so how would you put them into the markup?
Some sample markup to demonstrate what I'm talking about:
<!-- this test id allows an integration test to verify that
the carrot 188271 is in fact green but exposes the id to the user -->
<tr id="testid-carrot-id-188271">
<td class="color">green</td>
<td class="size">doesn't matter</td>
</tr>
I would never leave code intended for testing in a live site. That's just bad principle and inviting hacking.
As long as your test IDs are formatted such that they're not colliding with other IDs on the page (IDs need to be unique) and aren't being referenced by any of the live code (if you can't determine that there's something larger wrong here) then there shouldn't be any difference in behavior between the test site with the IDs and the live site without them.
In my opinion, the best practice is to design such that your test code executes correctly on your development site and you know that removing it doesn't harm your live site. I'd be concerned if my site needed to have the live version tested regularly to make sure it's working right.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With