I have many automated integration tests. Some of them are negative-case tests, which make sure that my system correctly reacts to being given data that it can't successfully use - such as being told to find resources on a remote host which does not exist.
However, this means I want the system under test to actually reach out and try to resolve the host, and I want it to always fail. But I don't know a way to guarantee that a given URL will result in a "Unknown Host" DNS response. I could try to make ludicrously-long and weird domain names, but that makes tests harder to read, and ultimately is still brittle in that someone could still bind something to that ludicrous domain name.
Is there a well-known "always-unresolvable" (but valid) domain or convention that I can use, without having to worry about the configuration of my (or anyone else's) DNS servers?
From RFC2606 (Reserved Top Level DNS Names)
- TLDs for Testing, & Documentation Examples
".invalid" is intended for use in online construction of domain names that are sure to be invalid and which it is obvious at a glance are invalid.
This was explained in more detail in RFC6761 (Special-Use Domain Names), with lots of SHOULD
s and MAY
s and only one MUST
:
DNS Registries/Registrars MUST NOT grant requests to register "invalid" names in the normal way to any person or entity.
Still, I think you SHOULD
be fine with using something.invalid
.
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