Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I unit test for machine specific behaviour?
    text
    copied!<p>I am testing a static method that builds a URL string after checking proxies and hostnames and all kinds of things. This method internally relies on the static flag <code>System.Net.Sockets.Socket.OSSupportsIPv6</code>. Because it's static, I cannot mock this dependency.</p> <p>EDIT: (This is simplified down a lot... I can't modify the structure of the method with the flag to accept a true/false).</p> <p>On XP development machines, the method under question returns a predictable string result (in this case, <a href="http://hostname/" rel="nofollow noreferrer">http://hostname/</a>.... ). Our build server, which support IPv6, returns a totally different result (it gives me something like <a href="http://192.168.0.1:80/..." rel="nofollow noreferrer">http://192.168.0.1:80/...</a>.). Please don't ask why - the point is that there are two different output types that vary on an operating system dependency.</p> <p>The test needs to validate that the returned hostname or IP address is valid. The outputs are easy to check. The problem is that I can only get one of the possible outputs, depending on which machine the test is run on.</p> <p>What's the best practice for writing the test in this case? Do I put an if statement in my test which checks the flag and then looks for the two different outputs? This seems sketchy to me because </p> <ol> <li><p>the test is behaving differently depending on the environment it's run in</p></li> <li><p>I'm basically coupling the test to the method, because you need to know the internals of the method to set up the two cases.</p></li> </ol> <p>Do I set up two tests, one for each environment, that simply pass if they're in the wrong environment? Do I write some complex regular expression that can separate out what kind of result it got and use more if/else logic to verify it?</p> <p>Any suggestions would help!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload