什么是用于单元测试的好的无效IP地址? [英] what is a good invalid IP address to use for unit tests?
问题描述
我正在为客户端库编写单元测试。我想测试连接无效端口和无效的IP。什么是一个好的IP地址使用,不会在某个地方被路由?我不想对运行单元测试的机器的网络做出任何假设。 LOCALHOST似乎是一个糟糕的选择,因为这是运行服务器组件的有效机器,我想分别测试一个无效的端口。是否在IPv4规范中的某处保留了INVALID-IP?
I am writing unit tests for a client library. I want to test connecting with an invalid port and an invalid ip. What is a good ip address to use that won't potentially be routed somewhere? I don't want to make any assumptions about the network the machine running the unit tests is on. LOCALHOST seems like a bad choice since that is the valid machine running the server component and I want to test an invalid port separately. Is there an INVALID-IP reserved somewhere in the IPv4 spec?
推荐答案
根据 RFC 5737 :
块192.0.2.0/24(TEST-NET -1),198.51.100.0/24(TEST-NET-2),
和203.0.113.0/24(TEST-NET-3)用于文档。
The blocks 192.0.2.0/24 (TEST-NET-1), 198.51.100.0/24 (TEST-NET-2), and 203.0.113.0/24 (TEST-NET-3) are provided for use in documentation.
这意味着您可以使用以下范围内的IP地址:
This means you can use pick an IP address from these ranges:
- 192.0 .2.0 - 192.0.2.255
- 198.51.100.0 - 198.51.100.255
- 203.0.113.0 - 203.0.113.255
这篇关于什么是用于单元测试的好的无效IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!