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面向对象程序设计>实验报告 一.实验前期准备 了解三种代码 伪代码 产品代码 测试代码 我们先写伪代码,伪代码 从意图层面来解决问题: 有了伪代码 我们用 ...
随机推荐
- 数据库故障处理优质文章汇总(含Oracle、MySQL、MogDB等)
数据库告警.紧急问题处理这些项目对于大多数朋友来讲应该不陌生了.从墨天轮社区整理的"最受DBA欢迎的技术文档合辑"系列中可以发现,大家对"故障诊断专题"的热情居 ...
- 封装JWT - 生成 jwt 和解析 jwt
1. ASP.NET Core 身份验证和授权验证的功能由Authentication,Authorization中间件提供 :app.UseAuthentication(),app.UseAutho ...
- day13-JavaDoc
JavaDoc JavaDoc命令是用来生成自己API文档的 参数信息 @author 作者名 @version 版本号 @since 指明需要最早使用的jdk版本 @param 参数名 @retur ...
- Litmus 实践:让群魔在混沌中乱舞,看 K8s 能撑到何时
对于云服务而言,如果系统出现异常,将会带来很大的损失.为了最大程度地降低损失,我们只能不断探寻系统何时会出现异常,甚至缩小到某些特定参数变化是否会造成系统异常.然而随着云原生的发展,不断推进着微服务的 ...
- Edge缓存清理操作说明
1. 打开Edge浏览器 2. 点击屏幕右上角三个点的按钮 3. 在出现的菜单里面选择"设置" 4. 在出现页面里面左侧选择"隐私.搜索和服务",然后右侧点击& ...
- php如何解决高并发
PHP交流群 656679284 为PHP广大爱好者提供技术交流,有问必答,相互学习相互进步! 1.应用和静态资源分离 将静态资源(js,css,图片等)放到专门的服务器中. 2.页面缓存 将应用 ...
- Nginx支持https访问
为了提高web应用的安全性,现在基本上都需要支持https访问.在此记录一下自己在nginx下的配置过程 安装Nginx这里就省略了 安装openssl模块 yum -y install openss ...
- python基础之__init__.py
如何使用 在 Python 中,当一个目录被作为包来使用时,它会在包中寻找一个名为 __init__.py 的文件.如果该文件存在,Python 会将它加载到内存中,并在其中执行所有的代码. __in ...
- hyperf的使用
hyperf是swoole的封装框架,用起来效率还是不错的. 使用方式看手册 https://hyperf.wiki/2.2/#/zh-cn/quick-start/install 其实是靠compo ...
- JVM源码分析-Java运行
最近在看Java并发编程实践和Inside JVM两本书,发现如果不真正的了解底层运作,那么永远是雾里看花.因此从http://openjdk.java.net/groups/hotspot/上下载了 ...