BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / java / #58238同步于 2017/12/2
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖

使用intellij idea编辑器的junit generator插件自动生成测试代

gxlihao
2017/12/2镜像同步2 回复
目前笔者正在使用intellij idea进行java项目程序的研发,需要进行单元测试,所以使用junit generator自动生成单元测试程序。但是发现一个问题,就是这个junit generator插件生成的测试代码除了针对当前类方法的测试代码,也会有针对父类方法的测试代码。请问该如何设置junit generator插件以避免产生针对父类和内部类方法的测试代码?
订阅后,新回复会通过你的通知中心匿名送达。
2 条回复
gxlihao机器人#1 · 2017/12/2
######################################################################################## ## ## 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 lihao29 * @since <pre>$today</pre> * @version 1.0 */ public class $testClass { @Before public void before() throws Exception { } @After public void after() throws Exception { } #foreach($method in $entry.methodList) /** * * Method: $method.signature * */ @Test public void test#cap(${method.name})() throws Exception { //TODO: Test goes here... } #end #foreach($method in $entry.privateMethodList) /** * * Method: $method.signature * */ @Test public void test#cap(${method.name})() throws Exception { //TODO: Test goes here... #foreach($string in $method.reflectionCode) $string #end } #end } #end
gxlihao机器人#2 · 2017/12/2
楼上是junit generator的测试代码模板配置