zoukankan      html  css  js  c++  java
  • 怎样在IDEA中使用JUnit4和JUnitGenerator V2.0自动生成测试模块

    前言----无法下载插件 请参考:https://my.oschina.net/u/2851681/blog/1789746

    解决办法:浏览器下载本地安装
    http://plugins.jetbrains.com/pluginManager/?action=download&id=org.intellij.plugins.junitgen&build=IU-162.2228.15&uuid=6a6cb9f5-4107-46d7-9b1c-d8205218a73b

    本文参考:https://www.cnblogs.com/libingbin/p/6007203.html

    maven项目对应的Output Path

    单项目
    ${SOURCEPATH}/../../test/java/${PACKAGE}/${FILENAME}
    聚合项目
    ${SOURCEPATH}/../../../../provider/src/test/java/${PACKAGE}/${FILENAME}

    junit4模板

    
    

    ########################################################################################
    ##
    ## Available variables:
    ## $entryList.methodList - List of method composites
    ## $entryList.privateMethodList - List of private method composites
    ## $entryList.fieldList - ArrayList of class scope field names
    ## $entryList.className - class name
    ## $entryList.packageName - package name
    ## $today - Todays date in MM/dd/yyyy format
    ##
    ## MethodComposite variables:
    ## $method.name - Method Name
    ## $method.signature - Full method signature in String form
    ## $method.reflectionCode - list of strings representing commented out reflection code to access method (Private Methods)
    ## $method.paramNames - List of Strings representing the method's parameters' names
    ## $method.paramClasses - List of Strings representing the method's parameters' classes
    ##
    ## You can configure the output class name using "testClass" variable below.
    ## Here are some examples:
    ## Test${entry.ClassName} - will produce TestSomeClass
    ## ${entry.className}Test - will produce SomeClassTest
    ##
    ########################################################################################
    ##
    #macro (cap $strIn)$strIn.valueOf($strIn.charAt(0)).toUpperCase()$strIn.substring(1)#end
    ## Iterate through the list and generate testcase for every entry.
    #foreach ($entry in $entryList)
    #set( $testClass="${entry.className}Test")
    ##

    package $entry.packageName; 

    import org.junit.Test;
    import org.junit.Before;
    import org.junit.After;

    
    

    /**
    * Created by auther on $today
    */
    //@RunWith(SpringJUnit4ClassRunner.class)
    //@ContextConfiguration(locations = "classpath:spring-config.xml")
    public class $testClass {

    static final Logger logger = LoggerFactory.getLogger($testClass .class);

    /**
    *
    */
    @Before
    public void before() throws Exception {

    }
    /**
    *
    */
    @After
    public void after() throws Exception {

    }

    #foreach($method in $entry.methodList)
    /**
    *
    */
    @Test
    public void test#cap(${method.name})() throws Exception {

    }

    #end

    #foreach($method in $entry.privateMethodList)
    /**
    *
    */
    @Test
    public void test#cap(${method.name})() throws Exception {

    #foreach($string in $method.reflectionCode)
    $string
    #end
    }

    #end
    }
    #end

     

     mac用户正确使用姿势(有其他方式不妨留言交流一下哈):

    目标类中全部方法,command+n 

    单个方法,选中方法command+shift+t

  • 相关阅读:
    Kafka-1
    消息队列
    分布式分类
    认识分布式
    数据库引擎
    Django插入多条数据—bulk_create
    Django中update和save()同时作用
    联合唯一去重的SQL
    Direct3D11学习:(三)Direct3D11初始化
    Direct3D11学习:(零)常见问题及解决方法整理
  • 原文地址:https://www.cnblogs.com/hhls/p/8822561.html
Copyright © 2011-2022 走看看