• 添加插件: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. 使用ssm(spring+springMVC+mybatis)创建一个简单的查询实例(三)(错误整理篇)

    使用ssm(spring+springMVC+mybatis)创建一个简单的查询实例(一) 使用ssm(spring+springMVC+mybatis)创建一个简单的查询实例(二) 以上两篇已经把流 ...

  2. int类型129转byte类型得到-127的解释

    package com.yygc.zhen.codeing_base; /** * @author zhen * @Date 2019/2/22 10:03 * 类型转换 */ public clas ...

  3. mysql慢查询----pt-query-digest详解慢查询日志(linux系统)

    一.简介 pt-query-digest是用于分析mysql慢查询的一个工具,它可以分析binlog.General log.slowlog,也可以通过SHOWPROCESSLIST或者通过tcpdu ...

  4. 基于Verilog的串口发送程序

    一.模块框图及基本思路 tx_bps_module:波特率时钟产生模块 tx_control_module:串口发送的核心控制模块 tx_module:前两个模块的组合 control_module: ...

  5. 强大的拖拽组件:React DnD 的使用

    强大的拖拽组件:React DnD 的使用 react.js 10.6k 次阅读  ·  读完需要 25 分钟 17 文章首发我的个人blog : 原文链接 学习 React DnD 的最初原因是阅读 ...

  6. git教程: 查看文件状态与修改内容

    转载:时光机穿梭 我们已经成功地添加并提交了一个readme.txt文件,现在,是时候继续工作了,于是,我们继续修改readme.txt文件,改成如下内容: Git is a distributed ...

  7. SpringBoot下如何配置实现跨域请求?

    一.什么是跨域请求? 跨域请求,就是说浏览器在执行脚本文件的ajax请求时,脚本文件所在的服务地址和请求的服务地址不一样.说白了就是ip.网络协议.端口都一样的时候,就是同一个域,否则就是跨域.这是由 ...

  8. PTA——完全数

    PTA 7-45 找完数 网友“云上明月”的程序: #include<stdio.h> int isPerfect(int num); int main() { ; int maxFact ...

  9. CSS样式补充第二天

    #p1{/*        border-width: 1px;*/        /*边框实线*/        /*border-style: solid;*/        /*边框虚线*/   ...

  10. vim编辑Makefile如何使用Tab

    因为用vim编辑代码设置了Tab键为4个空格,但有时候我们需要编写Makefile,必须使用Tab,同时也不想设置set noexpandtab. 其实可以先Ctrl_v组合键,再按Tab键盘,这样我 ...