感覺本文前部分配置太過繁瑣,大家可以參考我的這篇文章http://www.cnblogs.com/SuMeng/p/8279879.html(junit在IDEA中使用--實踐篇),用添加maven依賴直接代替前面的配置,實踐篇是基於spring的,本篇是針對普通項目,大家可以結合兩篇來參考
背景
我在開發haoop時,IDEA自帶的junit3不知道為什么不能用,所以改用junit4
步驟
添加插件:File->Settings->Plugins
設置生成模式:File->Settings->Other Settings
修改模板:File->Settings->Other Settings->Junit Generator->Junit4注意:還是把package 整行刪掉吧!!!!!!!!!!!!!!!!!!!!!!
方法一:右擊類名-->goto-->test-->create test(此方法不需要上面的步驟)
方法二:右擊類名-->generate,直接就按照模板生成了(此方法需要上面的步驟)
這是被測試的類HdfsClientDemo
public class HdfsClientDemo {
FileSystem fs = null;
public void init() throws URISyntaxException, IOException, InterruptedException {
Configuration conf = new Configuration();
fs = FileSystem.get(new URI("hdfs://192.168.32.201:9000"),conf,"hadoop"); //最后一個參數為用戶名
}
public void testUpLocalFile() throws IllegalArgumentException, IOException {
fs.copyFromLocalFile(new Path("e:/kk.xml"),new Path("/laji.bal.copy111"));
fs.close();
}
public void testDownLoad() throws IllegalArgumentException, IOException {
fs.copyToLocalFile(new Path("/kk.xml.copy"), new Path("e:/BaiduYunDownload"));
fs.close();
}
public static void main(String STR[]) throws URISyntaxException, IOException, InterruptedException {
FileSystem fs = null;
Configuration conf = new Configuration();
fs = FileSystem.get(new URI("hdfs://192.168.32.201:9000"),conf,"hadoop");
fs.copyFromLocalFile(new Path("e:/kk.xml"),new Path("/laji.bal.copy123"));
fs.close();
}
}
create new test后的樣子
需要自己添加上代碼