java单元测试squareTest使用以及gett的方法覆盖率提高

更新时间:2023-06-25 17:29:17 阅读: 评论:0

java单元测试squareTest使⽤以及gett的⽅法覆盖率提⾼⽬的:提⾼单测覆盖率
该基础类可覆盖原始类的所有get,t,is开头的⽅法
package;/**
* @Classname BaVoEntityTest.java
* @Description TODO
弹性限度* @Date 2021/8/17 11:28
* @Created by wangxutao1
* @Mail to
*/
import Test;
import RunWith;
import MockitoJUnitRunner;
import IntrospectionException;
import PropertyDescriptor;
import*;
import*;
public abstract class BaVoEntityTest<T>{
abstract T getT();
public void testGetAndSet()throws IllegalAccessException, InstantiationException, IntrospectionException,
InvocationTargetException, ClassNotFoundException, NoSuchMethodException {
T t =getT();
Class modelClass = t.getClass();
Object obj = wInstance();
Field[] fields = DeclaredFields();
for(Field field : fields){
// 设置私有变量可以访问
field.tAccessible(true);
}
Method[] declaredMethods = DeclaredMethods();
亚人酱有话要说for(Method method : declaredMethods){
// 覆盖get的⽅法
Name().startsWith("get")){
Object getResult = method.invoke(obj);
}
//覆盖 is⽅法
el Name().startsWith("is")){
Object invoke = method.invoke(obj);
}
// 覆盖所有的t⽅法
el Name().startsWith("t")){
String field = Name().substring(0+3).toLowerCa();
Object canshu =null;
for(Field f : fields){
Name().toLowerCa().equals(field)){
/
// 属性获取
canshu = f.get(obj);
}
}
Object invoke = method.invoke(obj, canshu);
}
}
}
@Test
@Test
public void getAndSetTest()throws InvocationTargetException, IntrospectionException,
岁月流年
InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException { stGetAndSet();
}
}
被测试的类如下
public class CacheConfig {
/**
* 缓存名称
*/
protected String name;
/**
* 过期时效
*/
protected long expired;
/**
* 本地缓存
*/
protected boolean local;
/**
* 缓存的集合数据
*/
protected boolean listable;
/**
* 为空的对象
*/
protected Object nullObject;
public CacheConfig(){
}
public CacheConfig(String name){
this.name = name;
}
public CacheConfig(String name,long expired){
this.name = name;
}
public CacheConfig(String name,long expired, Object nullObject){
this.name = name;
this.nullObject = nullObject;
}
public CacheConfig(String name,long expired,boolean local,boolean listable){
this.name = name;
this.local = local;交通安全手抄
this.listable = listable;
}
public CacheConfig(String name,long expired,boolean local, Object nullObject){
this.name = name;
this.local = local;
this.listable = listable;
this.nullObject = nullObject;
}
public String getName(){
public String getName(){
return name;
}
public void tName(String name){
this.name = name;
}
public long getExpired(){
return expired;
}
public void tExpired(long expired){
}
public boolean isLocal(){
return local;
}
public void tLocal(boolean local){
this.local = local;
}
public boolean isListable(){
return listable;
}
public void tListable(boolean listable){
this.listable = listable;
}
public Object getNullObject(){
return nullObject;
}江苏小高考时间
public CacheConfig nullObject(Object nullObject){
this.nullObject = nullObject;
return this;
}
@Override public String toString(){
final StringBuilder sb =new StringBuilder("CacheConfig{");        sb.append("name='").append(name).append('\'');
sb.append(", expired=").append(expired);
sb.append(", local=").append(local);
我的梦想作文800字sb.append(", listable=").append(listable);
sb.append(", nullObject=").append(nullObject);
sb.append('}');
String();
}
}
⽣成的测试类如下所⽰
public class CacheConfigTest extends BaVoEntityTest<CacheConfig>{
@Override
CacheConfig getT(){
return new CacheConfig();
}
private CacheConfig cacheConfigUnderTest;
@Before
public void tUp(){
cacheConfigUnderTest =new CacheConfig("name",0L,fal,fal);
}
@Test
public void testToString(){
// Setup
// Run the test
final String result = String();
/
/ Verify the results
asrtThat(result).isNotEqualTo("result");
}
}
想要更快速的话修改square的模板
该⾏修改为红框⾥的模板
耽美虐身public class ${sourceClass.name}Test extends BaVoEntityTest<${sourceClass.name}>{
@Override
${sourceClass.name}getT(){
如何添加字体return new ${sourceClass.name}();
}

本文发布于:2023-06-25 17:29:17,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/1037812.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:缓存   修改   覆盖   访问   高考   覆盖率
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图