Junit和Mockito测试Fileutils.copyurltofile
我如何使用Junit和Mockito编写单元测试,以简单地使用以下方法,
public class FileUtil {
public void copyURLToFile(String url, String filepath) {
try {
File file = new File(filepath);
FileUtils.copyURLToFile(new URL(url), file);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
但我不确定这是对的。
public class FileUtilTest {
private static final String TEST_URL = "http://www.test_url.com";
private static final String FILEPATH = "tst/test_files/test_file.txt";
FileUtil fileUtil;
@Test
public void copyURLToFileTest() throws IOException {
File file = new File(FILEPATH);
FileUtils.copyURLToFile(new URL(TEST_URL), file);
fileUtil.copyURLToFile(TEST_URL,FILEPATH);
}
}
有人可以请建议吗?
How can I write the unit test using JUnit and Mockito for a method as simple as the following
public class FileUtil {
public void copyURLToFile(String url, String filepath) {
try {
File file = new File(filepath);
FileUtils.copyURLToFile(new URL(url), file);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Here is what I have written but I'm not sure if it's right or not.
public class FileUtilTest {
private static final String TEST_URL = "http://www.test_url.com";
private static final String FILEPATH = "tst/test_files/test_file.txt";
FileUtil fileUtil;
@Test
public void copyURLToFileTest() throws IOException {
File file = new File(FILEPATH);
FileUtils.copyURLToFile(new URL(TEST_URL), file);
fileUtil.copyURLToFile(TEST_URL,FILEPATH);
}
}
Can someone please advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论