########################################################################################
##
## 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. webpack中 loader和plugin的区别

    首先 ,loader 是文件加载器,能够加载资源文件,并对文件进行一些处理,如翻译,压缩 ,最终一起打包到指定的文件中 :loader 运行在打包项目之前 : plugin 是插件 ,plugin赋予 ...

  2. 14 Positional Encoding (为什么 Self-Attention 需要位置编码)

    博客配套视频链接: https://space.bilibili.com/383551518?spm_id_from=333.1007.0.0 b 站直接看 配套 github 链接:https:// ...

  3. 数据运算中关于字符串""的拼接问题

    例子中准备了3种类型数据,分别针对是否在运算存在空字符串参与运算进行了演示,结果如下: 1 int x = 10; 2 double y = 20.2; 3 long z = 10L; 4 Syste ...

  4. spring boot下跨域安全配置

    1 @Bean 2 public FilterRegistrationBean corsFilter() { 3 final UrlBasedCorsConfigurationSource sourc ...

  5. 深度学习入门笔记——DataLoader的使用

    如何使用数据集DataSet? 在介绍DataLoader之前,需要先了解数据集DataSet的使用.Pytorch中集成了很多已经处理好的数据集,在pytorch的torchvision.torch ...

  6. Selenium弹框处理

    Selenium中有三种弹框,本文介绍了处理三种弹框的方法 一.Selenium三种弹框 alert:用来提示,显示一个带有指定消息和确认按钮的警告框 confirm:用于确认,显示一个带有指定消息和 ...

  7. Oracle HR样例数据库建立

    在视频的学习过程中,老师用到了HR样例数据库,但是我发现我的样例数据库中没有HR样例数据库,可能是在安装的时候漏掉了哪个环节,所以只能补救一下 如何判断自己是否有HR样例数据库呢?操作代码如下所示 第 ...

  8. 题解:CSP-S2020] 函数调用

    题解:CSP-S2020] 函数调用 一句话题意:给定一个有初始值的序列,支持如下三种操作: 1.单点加 2.全局乘 3.递归某些操作1.2.3 求最终的序列. 标签:topsort,动态规划,转化贡 ...

  9. php在大并发下redis锁实现

    在现如今电商盛行的时期,会出现很多促销活动,最为常见的就是秒杀.在秒杀系统中最为常见的问题就是会出现超卖的情况,那么如何来杜绝超卖的情形了,在业务逻辑层面可以使用缓存以及加锁的手法来避免超卖的情形. ...

  10. 基于sqli-labs Less-1的sql联合注入详解

    SQLi Labs 是一个专为学习和测试 SQL 注入漏洞设计的实验平台,旨在帮助安全研究人员.开发者和网络安全爱好者深入理解并实践各种 SQL 注入攻击.该平台提供了一系列精心设计的实验环境,模拟真 ...