########################################################################################
##
## 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
#macro (lowerCap $strIn)$strIn.valueOf($strIn.charAt(0)).toLowerCase()$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 cn.vv.web.vdc.BaseTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.MockitoAnnotations;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; /**
* @see $entry.packageName.${entry.className} Tester.
* @author zhongmaming
* @date $today
* @version 1.0
*/
@AutoConfigureMockMvc
public class $testClass extends BaseTest { @InjectMocks
private ${entry.className} #lowerCap(${entry.className}); @Autowired
private MockMvc mvc; @Before
public void setUp() throws Exception {
//build MockMvc instance
mvc = MockMvcBuilders.standaloneSetup(#lowerCap(${entry.className})).build();
MockitoAnnotations.initMocks(this);
} @After
public void tearDown() throws Exception {
} #foreach($method in $entry.methodList) /**
* @see $entry.packageName.${entry.className}#$method.signature
*/
@Test
public void test#cap(${method.name})() throws Exception {
this.mvc.perform(post("/api/crawl2vdc")
.characterEncoding("UTF-8")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON).content("{}"))
.andExpect(status().isOk())
.andDo(print()).andReturn().getResponse().getContentAsString();
}
#end #foreach($method in $entry.privateMethodList) /**
* @see $entry.packageName.${entry.className}#$method.signature
*/
@Test
public void test#cap(${method.name})() throws Exception {
#foreach($string in $method.reflectionCode)
$string
#end }
#end }
#end
########################################################################################
##
## 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
#macro (lowerCap $strIn)$strIn.valueOf($strIn.charAt(0)).toLowerCase()$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;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.powermock.modules.junit4.PowerMockRunner; /**
* @see $entry.packageName.${entry.className} Tester.
* @author zhongmaming
* @date $today
* @version 1.0
*/
@RunWith(PowerMockRunner.class)
public class $testClass{ @InjectMocks
private ${entry.className} #lowerCap(${entry.className}); @Before
public void setUp() throws Exception {
} @After
public void tearDown() throws Exception {
} #foreach($method in $entry.methodList) /**
* @see $entry.packageName.${entry.className}#$method.signature
*/
@Test
public void test#cap(${method.name})() throws Exception {
}
#end #foreach($method in $entry.privateMethodList) /**
* @see $entry.packageName.${entry.className}#$method.signature
*/
@Test
public void test#cap(${method.name})() throws Exception {
#foreach($string in $method.reflectionCode)
$string
#end }
#end }
#end

JunitGenerator的更多相关文章

  1. 怎样在IDEA中使用JUnit4和JUnitGenerator V2.0自动生成测试模块

     因为项目的需要,所以研究了一下自动生成测试代码.将经验记录下来,总会有用的.我个人认为,好记性不如多做笔记多反思总结. 1.    前提条件 开发环境已正确配置 工程已解决JUnit依赖关系(pom ...

  2. 25.怎样在IDEA中使用JUnit4和JUnitGenerator V2.0自动生成测试模块

    转自:https://blog.csdn.net/wangyj1992/article/details/78387728 因为项目的需要,所以研究了一下自动生成测试代码.将经验记录下来,总会有用的.我 ...

  3. Intellij idea添加单元测试工具

    1.idea 版本是14.0.0 ,默认带有Junit,但是不能自动生成单元测试,需要下载JunitGererator2.0插件 2.Settings -Plugins,下载 JunitGenerat ...

  4. idea 插件的使用 进阶篇

    CSDN 2016博客之星评选结果公布    [系列直播]零基础学习微信小程序!      "我的2016"主题征文活动   博客的神秘功能 idea 插件的使用 进阶篇(个人收集 ...

  5. IDEA中利用JUnit进行单元测试

    打开IntelliJ IDEA工具,Alt+Ctrl+S,打开设置窗口,点击进入Plugins. 从插件资源库中搜索JunitGenerator V2.0版本

  6. Intellij IDEA 杂记

    添加JUnit File > Settings > Plugins > Browse repositories > 搜索junit ,安装JunitGenerator V2 重 ...

  7. Intellj idea 安装JUnit

    1.file-Settings-Plugins-Browse repositories-HTTP Proxy Settings将No proxy改成Auto-detect proxy settings ...

  8. Intellj IDEA 简易教程

    Intellj IDEA 简易教程 目录 JDK 安装测试 IDEA 安装测试 调试 单元测试 重构 Git Android 其他 参考资料 Java开发IDE(Integrated Developm ...

  9. 【Selenium】idea的selenium环境配置

    1.maven配置 下载地址:http://maven.apache.org/download.cgi# 下载内容:apache-maven-3.5.0-bin.zip 环境变量:M2_HOME:E: ...

  10. 20175209 实验二《Java面向对象程序设计》实验报告

    20175209 实验二<Java面向对象程序设计>实验报告 一.实验前期准备 了解三种代码 伪代码 产品代码 测试代码 我们先写伪代码,伪代码 从意图层面来解决问题: 有了伪代码 我们用 ...

随机推荐

  1. kotlin更多语言结构——>注解

    注解声明 注解是将元数据附加到代码的方法.要声明注解,请将 annotation 修饰符放在类的前面 annotation class Fancy 注解的附加属性可以通过用元注解标注注解类来指定 - ...

  2. kotlin类与对象——>委托、委托属性

    1.委托 1.1 委托的实现 委托模式已经证明是实现继承的一个很好的替代方式,而 Kotlin 可以零样板代码地原生支持它. Derived 类可以通过将其所有公有成员都委托给指定对象来实现一个接口 ...

  3. CMDB实践指南:项目规划与实施策略解析

    随着现代企业IT系统的日益复杂,如何有效管理这些庞大的IT资产和资源,成为每个企业必须面对的重要问题.CMDB应运而生,帮助企业集中管理IT资源,维护系统的稳定性,并支持故障排查与决策制定.本文将深入 ...

  4. 可重入锁ReentrantLock

    ReentrantLock 重入锁,是实现Lock 接口 的一个类,也是在实际编程中使用频率很高的一个锁,支持重入性,表示能够对共享资源重复加锁,即当前线程获取该锁后再次获取不会被阻塞. 要想支持重入 ...

  5. Oracle 11.2 RAC 删除节点

    软硬件环境:与上一篇文章一致: 一般对 CRS 层面数据结构做重要操作之前一定要先备份 OCR  [root@vastdata4 ~]# ocrconfig -manualbackup vastdat ...

  6. 生成文本聚类java实现1

    本章主要的学习是中文分词 和两种统计词频(传统词频和TF-IDF算法 ) 的方法. 学习目的:通过N多的新闻标题 or 新闻摘要 or 新闻标签,生成基本的文本聚类,以便统计当天新闻的热点内容. 扩展 ...

  7. 卧槽,WebStorm现在免费啦!

    前言 就在昨天1024程序员节,JetBrains突然宣布WebStorm现在对非商业用途免费啦.以后大家再也不用费尽心思的去找破解方法了,并且公告中的关于非商业用途定义也很有意思. 关注公众号:[前 ...

  8. 【分享】用typescript结合react编写代码,引入第三方库模块报错的解决办法

    1.前提 我用  npx create-react-app my-react-ts-app --template typescript  创建了一个应用,加了typescript到项目中; 问题来了, ...

  9. win10下端口映射设置内网别人访问本机安装的vmware默认NAT网络

    用管理员权限打开powershell或者cmd,命令如下 netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=主 ...

  10. CentOS 7环境下DM8数据库的安装与配置

    一.环境准备 首先,确保你的系统已经安装了CentOS 7,并且具有足够的磁盘空间和内存来支持DM8数据库的运行.此外,你还需要具备管理员权限,以便进行后续的安装和配置操作. 二.下载DM8安装包 访 ...