JunitGenerator
########################################################################################
##
## 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的更多相关文章
- 怎样在IDEA中使用JUnit4和JUnitGenerator V2.0自动生成测试模块
因为项目的需要,所以研究了一下自动生成测试代码.将经验记录下来,总会有用的.我个人认为,好记性不如多做笔记多反思总结. 1. 前提条件 开发环境已正确配置 工程已解决JUnit依赖关系(pom ...
- 25.怎样在IDEA中使用JUnit4和JUnitGenerator V2.0自动生成测试模块
转自:https://blog.csdn.net/wangyj1992/article/details/78387728 因为项目的需要,所以研究了一下自动生成测试代码.将经验记录下来,总会有用的.我 ...
- Intellij idea添加单元测试工具
1.idea 版本是14.0.0 ,默认带有Junit,但是不能自动生成单元测试,需要下载JunitGererator2.0插件 2.Settings -Plugins,下载 JunitGenerat ...
- idea 插件的使用 进阶篇
CSDN 2016博客之星评选结果公布 [系列直播]零基础学习微信小程序! "我的2016"主题征文活动 博客的神秘功能 idea 插件的使用 进阶篇(个人收集 ...
- IDEA中利用JUnit进行单元测试
打开IntelliJ IDEA工具,Alt+Ctrl+S,打开设置窗口,点击进入Plugins. 从插件资源库中搜索JunitGenerator V2.0版本
- Intellij IDEA 杂记
添加JUnit File > Settings > Plugins > Browse repositories > 搜索junit ,安装JunitGenerator V2 重 ...
- Intellj idea 安装JUnit
1.file-Settings-Plugins-Browse repositories-HTTP Proxy Settings将No proxy改成Auto-detect proxy settings ...
- Intellj IDEA 简易教程
Intellj IDEA 简易教程 目录 JDK 安装测试 IDEA 安装测试 调试 单元测试 重构 Git Android 其他 参考资料 Java开发IDE(Integrated Developm ...
- 【Selenium】idea的selenium环境配置
1.maven配置 下载地址:http://maven.apache.org/download.cgi# 下载内容:apache-maven-3.5.0-bin.zip 环境变量:M2_HOME:E: ...
- 20175209 实验二《Java面向对象程序设计》实验报告
20175209 实验二<Java面向对象程序设计>实验报告 一.实验前期准备 了解三种代码 伪代码 产品代码 测试代码 我们先写伪代码,伪代码 从意图层面来解决问题: 有了伪代码 我们用 ...
随机推荐
- 前端工程化解决方案webpack使用小结
前端工程化解决方案webpack,模块化.组件化.规范化.自动化,使得前端开发更加高效. 功能:代码压缩混淆.处理浏览器端js的兼容性.以模块化的方式处理项目中的资源 webpack插件:clean- ...
- ProxyPin 抓包,原来可以这么简单!
你是否还在为网络请求的抓包发愁?其实,ProxyPin 可以让抓包操作变得异常简单!不需要复杂的设置,也不用繁琐的配置,轻松几步就能实现.让我们一起来看看吧! 抓包操作常用于测试网络请求.分析接口 ...
- spring boot 官网提供所有组件
所有资源来自于官网:https://start.spring.io/,在此整理只是为了方便查看 Developer Tools Spring Boot DevToolsProvides fast ap ...
- SaaS架构:中央库存系统架构设计
大家好,我是汤师爷~ 近年来,越来越多的零售企业大力发展全渠道业务.在销售额增长上,通过线上的小程序.直播.平台渠道等方式,拓展流量变现渠道.在会员增长方面,通过多样的互动方式,全渠道触达消费者,扩大 ...
- 【转】sqlplus/RMAN/lsnrctl 等工具连接缓慢
AIX上sqlplus /as sysdba rman target / 或者lsnrctl start时或者通过sqlplus system/oracle@orcl这样通过监听连接等方式来登陆时非常 ...
- 云原生周刊:Kubernetes v1.30 一瞥 | 2024.3.25
开源项目推荐 Retina Retina 是一个与云无关的开源 Kubernetes 网络可观测平台,它提供了一个用于监控应用程序运行状况.网络运行状况和安全性的集中中心.它为集群网络管理员.集群安全 ...
- KubeSphere 开源社区 2022 年度回顾与致谢
2022 年,国内的云原生技术生态日趋完善,细分技术项目也不断涌现,形成了完整的支撑应用云原生化的全生命周期技术体系.基础设施即代码.微服务.Serverless 等技术,促使基础设施资源向更加灵活弹 ...
- sqluldr2linux64.bin命令行下的Oracle数据导出工具
sqluldr2.bin是Oracle数据库下,数据导出的工具 (1)query导出 ./sqluldr2.bin user=用户/密码@主机IP/数据库名 query="select ...
- 一文搞懂 ARM 64 系列: PACISB
1 PAC AMR64提供了PAC(Pointer Authentication Code)机制. 所谓PAC,简单来说就是使用存储在芯片硬件上的「密钥」,一个「上下文」,与「指针地址」进行加密计算, ...
- .NET斗鱼直播弹幕客户端(上)
现在直播平台由于弹幕的存在,主播与观众可以更轻松地进行互动,非常受年轻群众的欢迎.斗鱼TV就是一款非常流行的直播平台,弹幕更是非常火爆.看到有不少主播接入弹幕语音播报器.弹幕点歌等模块,这都需要首先连 ...