Answer: Yes, it's necessary.
Step-by-step explanation: A horizontal line test's purpose is to check if whether the function has an inverse. Moreover, the horizontal line test also ensures if that inverse is a function.
If you're talking about a vertical line test, its purpose is to determine whether a curve on the graph represents a function. If the vertical line touches more than one point on the graph, then it is a function. An example is below.
Hopefully, this helps!