0. setting--->plugins--->brose repostories-->輸入JUnitGenerator V2.0
1.junit generator自動生成測試代碼缺省和java類在同一報下,不匹配maven項目標准測試目錄。修改設置,查詢junit Generator
2.outpath設置為${SOURCEPATH}/../../test/java/${PACKAGE}/${FILENAME}【default template選junit4】
3.點擊Properties最右側的Junit4,修改模板。將@since <pre>$date</pre> 改為@since <pre>$today</pre>。 這樣就不會出現日期亂碼。
package test.$entry.packageName; 改為 package $entry.packageName; 符合maven的對應目錄。
4.自動生成測試代碼的快捷鍵:在待編寫測試的java類源碼塊上按快捷鍵:alt+insert 或ctrl+shift+T
######################################################################################## ## ## 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; /** * ${entry.className} Tester. * @author zhongmaming * @date $today * @version 1.0 */ public class $testClass { @Before public void before() throws Exception { } @After public void after() throws Exception { } #foreach($method in $entry.methodList) /** * @see $entry.packageName.${entry.className}#$method.signature */ @Test public void test#cap(${method.name})() throws Exception { //TODO: Test goes here... } #end #foreach($method in $entry.privateMethodList) /** * */ @Test public void test#cap(${method.name})() throws Exception { #foreach($string in $method.reflectionCode) $string #end } #end } #end
