IntelliJ IDEA 2016 Maven项目配置JUnit

栏目: Java · 发布时间: 7年前

内容简介:IntelliJ IDEA 2016 Maven项目配置JUnit

IntelliJ IDEA 2016 Maven项目配置JUnit

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

IntelliJ IDEA 2016 Maven项目配置JUnit

  • 修改模板: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
  • 结构图
IntelliJ IDEA 2016 Maven项目配置JUnit

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>

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

x86/x64体系探索及编程

x86/x64体系探索及编程

邓志 / 电子工业出版社 / 2012-10-1 / 119.00元

本书是对Intel手册所述处理器架构的探索和论证。全书共五大部分,从多个方面对处理器架构相关的知识进行了梳理介绍。书中每个章节都有相应的测试实验,所运行的实验例子都可以在真实的机器上执行。 通过阅读本书,读者应能培养自己动手实验的能力。如果再有一些OS方面的相关知识,基本上就可以写出自己简易的OS核心。 本书适合有一定的x86基础知识,且对了解处理器架构及编程感兴趣的读者阅读。一起来看看 《x86/x64体系探索及编程》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

MD5 加密
MD5 加密

MD5 加密工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器