I'm in the process of writing a test for a class that downloads a file using ftp and then does some processing on the information in the file after it's been downloaded. My problem is this: how do I test the method that does the actual ftp download? Do I download the file using a completely different method, say the command line, then when I download the file through the code generate a hash for both files and check for equality? I don't have a lot of experience using JUnit, but I'm trying to learn. I can figure out how to test the rest, I just haven't been able to devise a way to test the actual ftp process.
Alex, The best way is to unit test everything else using a mock FTP. EasyMock and JMock are frameworks that help you create these pretend objects.
Once you know everything else is working, you can write an integration or end to end test that actually does the FTP. That way your main unit tests are repeatable and independent of the network, but you are still testing the FTP part for "real."
Thanks. I had figured out to separate the other tests from the ftp process, but I ran into a wall trying to figure out how to test the ftp. Fortunately, all the ftp code is already isolated to a single method so I won't have to use a mock framework for the other methods, as the only method that calls the ftp method is the class controller method.