• 添加插件: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 gcc args

    参数详解无选项编译链接    将test.c预处理.汇编.编译并链接形成可执行文件.这里未指定输出文件,默认输出为a.out.    例子用法:    gcc test.c 无选项链接    gcc ...

  2. wishhack 玩法概览

    抢流量玩法 超级店长玩法 https://www.wishhack.com/article/50.html https://www.wishhack.com/article/43.html

  3. vscode 创建.net core mvc

    cd 进一个文件夹 1,创建一个sln 工程文件  [ dotnet new sln -n Demo1 ] 2,创建一个mvc项目 [ dotnet new mvc -n Demo1.Web ] 3, ...

  4. 在myeclipse中使用./和../遇到的问题

    今天用ajax验证的时候,ajax的代码一直不起作用,我在浏览器里打开了开发者模式,错误的原因是找不到"jquery-1.8.3.min.js",但是我的目录结构都没有问题. &l ...

  5. linux安装mysql图文教程

    ---恢复内容开始--- 1.下载mysql [root@localhost ~]# yum install mysql mysql-server 输入y 输入y 输入y 下载完成 接下来我们要使用w ...

  6. springcloud Ribbon学习笔记一

    上篇已经介绍了如何开发eureka服务并让多个服务进行相互注册,接下来记录如何开发一个服务然后注册到eureka中并能通过ribbon成功被调用 开发一个用户服务并注册到eureka中,用户服务负责访 ...

  7. HTML5:表格相关标记及其属性

    表格相关标记及其属性 <table>:表格,包括以下属性 属性 说明 width 宽度(有像素和百分比两种表示方法) height 高度(有像素和百分比两种表示方法) border 边框粗 ...

  8. 【webdriver自动化】Python数据驱动工具DDT

    一.Python数据驱动工具ddt 1.  安装 ddt pip install ddt DDT是 “Data-Driven Tests”的缩写 资料:http://ddt.readthedocs.i ...

  9. video自动填充满父级元素

    想要video能自动填充慢父div的大小,只要给video标签加上style="width= 100%; height=100%; object-fit: fill"即可. obj ...

  10. 微信小程序跳转(当我们不知道是普通页面还是tabbar)

    页面跳转一般我们都用wx.navigateTo 或者wx.redirectTo等,当页面为tabbar的某一个页面时, 我们盖如何兼容呢我处理的方式为在navigateTo的fail方法中执行wx.s ...