• 添加插件:File->Settings->Plugins

  • 设置生成模式:File->Settings->Other Settings

  • 修改模板:File->Settings->Other Settings->Junit Generator->Junit4
#if( $entry.packageName.length()>0)package test.$entry.packageName; #end
* @author:Hunter
* @since:$today
* @version 1.0
  • 在代码上右键Generate
  • 结构图



src/main/java:source root

src/test/java:test root

  • Main.java
/**
* Created by Hunter on 2016/07/19.
*/
import org.apache.hadoop.conf.Configuration; public class Main { public static void main(String[] args){
for(String arg:args)
System.out.println(arg); } public static String getColor(){
Configuration conf =new Configuration();
conf.addResource("Configuration-1.xml");
return conf.get("color");
} public static int getSize(){
Configuration conf =new Configuration();
conf.addResource("Configuration-1.xml");
return conf.getInt("size",0);
}
}
  • 自动生成MainTest.java


import org.junit.Test;
import org.junit.Before;
import org.junit.After; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.hamcrest.Matchers.*; import org.apache.log4j.Logger; /**
* Main Tester.
*
* @author:Hunter
* @since:7/19/2016
* @version 1.0
*/
public class MainTest {
private static Logger logger=Logger.getLogger(MainTest.class); @Before
public void before() throws Exception {
logger.info("Test start……");
} @After
public void after() throws Exception {
logger.info("Test end……");
} /**
*
* Method: main(String[] args)
*
*/
@Test
public void testMain() throws Exception {
String[] args=new String[2];
args[0]="Hello";
args[1]="world";
Main.main(args);
} /**
*
* Method: getColor()
*
*/
@Test
public void testGetColor() throws Exception {
assertThat(Main.getColor(),is("yellow"));
} @Test
public void testGetSize() throws Exception{
assertEquals(Main.getSize(),10);
} }
  • Pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com.ggz</groupId>
<artifactId>MRTest</artifactId>
<version>1.0-SNAPSHOT</version> <dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency> <dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
</project>

IDEA2016 maven项目配置Junit的更多相关文章

  1. maven项目配置findbugs插件 使用git钩子控制代码的提交

    maven项目配置findbugs插件对代码进行静态检测 当发现代码有bug时,就不让用户commit代码到远程仓库里 没有bug时才可以commit到远程仓库中 (1)新建maven项目 ,配置fi ...

  2. maven项目配置使用jdk1.8进行编译的插件

    在使用Maven插件编译Maven项目的时候报了这样一个错:[Java source1.5不支持diamond运算符,请使用source 7或更高版本以启用diamond运算符],这里记录下出现这个错 ...

  3. maven 项目配置

    创建java web的maven项目方法有两种,一是先创建maven项目,再选择jdk 和 dynamic web 运行环境 ,二是创建java项目,然后转化为maven项目 1.将普通java项目转 ...

  4. apache log4j日志工具使用入门[maven 项目配置]

    简单的介绍下Maven项目中有关org.apache.log4j.Logger的使用.[1]首先我们需要找到 org.apache.log4j.Logger的坐标,并配置到POM.xml <de ...

  5. maven项目配置框架

    任何一个maven项目都会继承一个默认的父pom配置:Super POM,详见:https://maven.apache.org/guides/introduction/introduction-to ...

  6. 【IDEA】本地新建Maven项目+配置Git和GitHub+代码上传和拉取到GitHub+其他IDEA和GitHub实战

    一.本地新建Maven项目并启动成功 1. 按照IDEA提供的模板,构建一个maven webapp的模板项目. 一路Next,到最后的finish.如下图. 2. 新建Tomcat,启动刚建立的项目 ...

  7. Maven项目配置Logback输出JSON格式日志

    最近,项目提出需求,日志需要固定输出为JSON格式,以便后端Flink程序解析. 项目背景 项目为简单的Maven项目,日志由Filebeat采集,因此不需要配置输出至Logstash. 下面为pom ...

  8. maven 项目配置到tomcat不能正常启动

    最近使用IntelliJ IDEA搭建公司项目,该项目是maven项目,加载jar和编译的时候没有任何异常,但是部署到tomcat上之后,就会出现如下异常: org.apache.catalina.L ...

  9. Maven项目配置外部依赖(本地依赖)

    加入有一些公共jar包只限于公司内部使用,不能暴露在外部时,有如下的方案: 1.搭建私有远程仓库(nexus) 2.使用http.ftp.共享地址,github地址等(主要是通过maven-deplo ...

随机推荐

  1. vs 设置自动缩进tab转换成空格

    工具   选项   文本编辑器    如下图  选中插入空格 使用技巧: 按Ctrl+K+F组合键,可以自动进行代码对齐.

  2. SVN 常见报错

    1.svn is out of date 出错原因:SVN服务器端的版本比你的版本要新,不允许提交.     解决方案1:右键你所要提交的文件,team-->update 更新最新版本 然后再提 ...

  3. centos6升级python

    CentOS 6中,默认安装了Python 2.6.而pip,jupyter这样的常用工具是不支持Python 2.6的.为了使用这些工具,就必须将Python 2.6升级到Python 2.7以上的 ...

  4. python语法之函数

    函数: 将特定功能代码编写在一个函数里 便于阅读和复用 对一组表达特定功能表达式的封装 使程序模块化 python内置函数: input(),print(),eval()... 函数定义 函数语法格式 ...

  5. CSS学习笔记-05 过渡模块的基本用法

    话说 1对情侣两情相悦,你情我愿.时机成熟,夜深人静...咳 ,如果就这么直奔主题,是不是有点猴急,所以,还是要来点前戏@. 铛 铛, 这个时候 过渡模块出现了. 划重点: 上代码: <!DOC ...

  6. python的format格式化

    使用方法:  '{}bbccc'.format(aa) = aabbcc, 用来代替python2中的%,即替换. 1.通过位置来指定替换 In [2]: '{0},{1}'.format('a', ...

  7. 解决ubuntu下firefox的flash全屏后不能恢复问题 ZT

    sudo mkdir /etc/adobe echo "OverrideGPUValidation=true" >~/mms.cfg sudo mv ~/mms.cfg /e ...

  8. 周强 201771010141《面向对象程序设计(java)》第四周学习总结

    实验目的与要求 (1) 理解用户自定义类的定义: (2) 掌握对象的声明: (3) 学会使用构造函数初始化对象: (4) 使用类属性与方法的使用掌握使用: (5) 掌握package和import语句 ...

  9. CentOS7 cannot find a valid baseurl for repo base

    找到文件夹: cd /etc/sysconfig/network-scripts/ 然后找ifcfg 开头的文件,挨个打开 里面有下面那些代码前三行的就是,添加后面DNS两行,保持并退出,然后继续执行 ...

  10. 解决Yii2中刷新网页时验证码不刷新的问题

    解决Yii2中刷新网页时验证码不刷新的问题 [ 2.0 版本 ] ljfrocky  2015-05-30 19:39:00  1304次浏览 5条评论 10110 在Yii2框架中,如果在表单中使用 ...