容错测试1-aop实现

发表于:2013-7-26 11:04

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:秦渊    来源:51Testing软件测试网采编

分享:

  <!--[if !supportLists]-->3.  <!--[endif]-->使用过程,大体分为3步,如下:

  <!--[if !supportLists]-->a)  <!--[endif]-->配置: 配置切面,选择mock触发点,配置连接点的逻辑,选择处理方式

<bean
id="mockAspect"
class="com.taobao.azeroth.util.MockTestAspect" >
<property name="sleepTime" value="0"/>
<property name="flag" value="false"/>
</bean>
<aop:config proxy-target-class="false" >
<aop:pointcut
id="springTestPointcut"
expression="execution(* com..Hello.hello(..))" />
<aop:aspect
id="aspectSpringSleep"
ref="mockAspect" order="100">
<aop:around
method="mockMethod"
pointcut-ref="springTestPointcut" />
</aop:aspect>
</aop:config>

  <!--[if !supportLists]-->b)  <!--[endif]-->脚本: 配置切面参数&调用被测试方法

  <!--[if !supportLists]-->c)  <!--[endif]-->执行策略: 是否要多线程&构造单个线程的参数&配置执行策略,运行

@Test
    public void test_01_thread_run(){        
       ThreadFactory thFac=new ThreadFactory();
       //配置切面信息
        mockAspect.setMockResult(11);
       ThreadTest th=new ThreadTest();
       th.setOwnerBean(hello);
       th.setMethodName("hello");
       th.setMockAspect(mockAspect);
       th.setThreadMockFlag(true);
//一个线程可以有n个校验服务
       AssertService as=new AssertService();
       //增加线程中的验证方法,直接可以定义
       as.setCheckMethod(this, "checkResult");
       th.addAssertService(as);
       //通过传单个mock thread来传参
       thFac.addThread(th);
       //同时启动5个线程来测试
       thFac.startThreads(5);
  }
    public void checkResult(Integer result){
       System.out.println("传入设置actual值得方法");
       result=result+1;
       assertThat("验证",result,greaterThan(10));
  }

  总结:使用AOP的方式来注入mock内容,可以使我们的测试代码更清晰,利于维护管理,也可以更好的扩展我们的mock时要进行的操作.

相关文章:

容错测试2-hsf mock方案

33/3<123
精选软件测试好文,快来阅读吧~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号