From: Ben Giddings Date: 2003-09-05T01:45:32+09:00 Subject: Re: [OT] Unit Tests and Encapsulation Wesley J. Landaker wrote: > What about some other extreme cases? Like, a class that plays a sound on a > speaker? How do you unit test that? Or, likewise, any class that > interfaces with the "world" "outside" your control? What if they are so > complex that you can't easily or acurately model them? What about output > that "needs" human interaction? I also regularly deal with cases that involve interfacing to external systems. If I want to test something that grabs a web page, what happens if due to network issues, my access times out? If what you're really interested in is not related to the network, then you can either test to see if you have the right URL and headers to fetch the web page, or fake the fetch and see if your code handles the data properly, but what if the web access is essential? An example would be a bit of code that tries to use some data to figure out what URL to use to get what it needs. The only way to test to see if that URL is correct is to see if the web page it fetches contains the data it expects. Because of the nature of the problem (the changing web), you can't tell by looking at the URL if it is correct, you need to see what it fetches. You could always retry if a network error occurs, but what if the error is a 500 series HTTP error (i.e. your URL was correct but the server is temporarily broken)? Are there general unit testing strategies for dealing with things outside the system you have control over? Ben