• 添加插件: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. learning makefile 定义命令包

  2. python-面向对象:类与类之间的关系和特殊成员

    # class Person: # def play(self, tools): # 通过参数的传递把另外一个类的对象传递进来 # tools.run() # print("很开心, 我能玩 ...

  3. yii2 中excel表导出

    首先下载phpexcel 在引入类文件(在web中index.php入口文件或者控制器中引入) require_once dirname(dirname(__FILE__)).'/excel/PHPE ...

  4. SQL-41 构造触发器

    题目描述 构造一个触发器audit_log,在向employees_test表中插入一条数据的时候,触发插入相关的数据到audit中.CREATE TABLE employees_test(ID IN ...

  5. Linux平台网络配置-----C语言

    上一期我们已经介绍了VM虚拟机安装CentOS 7系统的步骤过程,这次就来看看使用Linux对初学者有什么障碍? 零基础学习C语言---Linux平台配置网络 用VM虚拟机启动Linux系统时出现的问 ...

  6. Linux基础知识_Shell编程笔记

    以下是一些 常用功能 , 基于 centos 6.5 x64 # cp /etc/localtime /etc/localtime.org # rm /etc/localtime # ln -s /u ...

  7. VC++封装的时间类

    一.使用方法 首先要在工程中加入TimeNow.cpp和TimeNow.h文件 1.把.cpp与.h文件放在放在工程文件夹. 2.项目(progect)-->属性(properties)--&g ...

  8. php批量检测和去掉bom头(转)

    <?php //有些php文件由于不小心保存成了含bom头的格式而导致出现一系列的问题.以下是批量清除bom头的代码 if (isset ( $_GET ['dir'] )) { //confi ...

  9. 软间隔分类——SVM

    引入:1. 数据线性不可分:2. 映射到高维依然不是线性可分3. 出现噪声.如图: 对原始问题变形得到#2: 进行拉格朗日转换: 其中α和r是拉格朗日因子,均有不小于0的约束.按照之前的对偶问题的推导 ...

  10. 几个特殊的IP地址

    1)私有地址     IP地址在全世界范围内唯一,看到这句话你可能有这样的疑问,像192.168.0.1这样的地址在许多地方都能看到,并不唯一,这是为何?Internet管理委员会规定如下地址段为私有 ...