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面向对象程序设计>实验报告 一.实验前期准备 了解三种代码 伪代码 产品代码 测试代码 我们先写伪代码,伪代码 从意图层面来解决问题: 有了伪代码 我们用 ...
随机推荐
- 2022年2月国产数据库排行榜:冠军宝座面临挑战,OceanBase 重返 TOP3
大家好!文章开始本是用"新春快乐!虎年吉祥!"和大家打个招呼,无奈时间过得太快而文章整理得很慢,眼看崭新的三月还有几天就到来,那就在这里祝屏幕前的你在三月比二月更优秀! 月初,20 ...
- 1. C#面试题 - Webservice和WebApi的区别
1. Webservice : 基于SOAP协议的,数据格式时XML,只支持http协议,不是开源的,只能部署在IIS上 2. Webapi 开源的,.net 平台
- amfe-flexible 包设置rem的基本值 vue 移动端适配方案
下载 安装 :npm i -S amfe-flexible gw:GitHub - amfe/lib-flexible: 可伸缩布局方案 下载 2 个第三方包即可实现移动端适配 amfe-flexib ...
- 65.说下vue3的使用感想(说些vue3对比vue3的方便之处)
vue3 使用了组合式API,setup 替换了选项式api ,不需要在多个api里面写代码了,而且使用了setup的语法糖,可以更加方便写代码 : vue3使用proxy替代了Object.defi ...
- Kali Linux 更新 一条命令搞定
Kali Linux 更新 一条命令搞定 sudo apt-get update && sudo apt-get upgrade && sudo apt-get dis ...
- 云原生周刊 | 在 Grafana 中显示 K8s Service 之间的依赖关系
开源项目推荐 Caretta 这个项目可以在 Grafana 监控面板中显示 K8s Service 之间的依赖关系.底层使用的是 eBPF,对应用无侵入. busuanzi 这是一个基于 Golan ...
- OpenFunction v0.8.0 发布:通过 Dapr Proxy 加速函数启动
相较于其他函数计算项目,OpenFunction 有很多独特的功能,其中之一便是通过 Dapr 与各种后端服务(BaaS)无缝集成.目前 OpenFunction 已经支持了 Dapr 的 pub/s ...
- KubeSphere v4 全解析:揭秘您最关心的 12 大热点问题
为了助力大家更顺畅地使用 KubeSphere v4,我们精心汇总了十二个开发者高频关注的热点问题,这些问题全面覆盖了功能特性.性能表现.兼容性考量.安全保障以及升级流程等关键方面.接下来,我们将为大 ...
- Java常见面试真题之中级进阶(HashMap篇)
前言 本来想着给自己放松一下,刷刷博客,突然被几道面试题难倒!说说Hashtable 与 HashMap 的区别?HashMap 中的 key 我们可以使用任何类作为 key 吗?HashMap 的长 ...
- TypeError: __init__() got an unexpected keyword argument 'XXXXXXXX'
解决方法:安装包的版本兼容问题,更新一下安装包的版本(如果在别的机器不报错,那就把不报错的这台机器上的安装包pip freeze > requirements.txt 下来,在报错的机器上安装一 ...