感受本文前部分配置太過繁瑣,你們能夠參考個人這篇文章http://www.cnblogs.com/SuMeng/p/8279879.html(junit在IDEA中使用--實踐篇),用添加maven依賴直接代替前面的配置,實踐篇是基於spring的,本篇是針對普通項目,你們能夠結合兩篇來參考html
背景java
我在開發haoop時,IDEA自帶的junit3不知道爲何不能用,因此改用junit4spring
步驟maven
添加插件:File->Settings->Pluginsoop
設置生成模式:File->Settings->Other Settings測試
修改模板:File->Settings->Other Settings->Junit Generator->Junit4注意:仍是把package 整行刪掉吧!!!!!!!!!!!!!!!!!!!!!!spa
方法一:右擊類名-->goto-->test-->create test(此方法不須要上面的步驟)插件
方法二:右擊類名-->generate,直接就按照模板生成了(此方法須要上面的步驟)3d
這是被測試的類HdfsClientDemoxml
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後的樣子
須要本身添加上代碼