junit在idea中的使用(1)--理论篇

 感觉本文前部分配置太过繁琐,大家可以参考我的这篇文章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后的样子

 

需要自己添加上代码

 

posted @ 2017-11-19 23:02  透明的红萝卜  阅读(4865)  评论(0编辑  收藏  举报