前言----無法下載插件 請參考: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