日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 前端技术 > javascript >内容正文

javascript

基于Spring开发的DUBBO服务接口测试

發(fā)布時(shí)間:2023/12/13 javascript 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 基于Spring开发的DUBBO服务接口测试 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

???????????? 基于Spring開(kāi)發(fā)的DUBBO服務(wù)接口測(cè)試

?

知識(shí)共享主要內(nèi)容:

1、 Dubbo相關(guān)概念和架構(gòu),以及dubbo服務(wù)程序開(kāi)發(fā)步驟。

2、 基于Spring開(kāi)發(fā)框架的dubbo服務(wù)接口測(cè)試相關(guān)配置。

3、 spring test+junit和spring test+TestNG兩種測(cè)試框架腳本編寫(xiě)方法。

?

一、??????? DUBBODUBBO架構(gòu)

1、????????? 什么是dubbo?DUBBO是一個(gè)分布式服務(wù)框架,致力于提供高性能和透明化的RPC遠(yuǎn)程服務(wù)調(diào)用方案,是阿里巴巴SOA務(wù)化治理方案的核心框架,每天為2,000+個(gè)服務(wù)提供3,000,000,000+次訪問(wèn)量支持,并被廣泛應(yīng)用于阿里巴巴集團(tuán)的各成員站點(diǎn)。

2、????????? DUBBO架構(gòu):

??????

二、??????? Dubbo務(wù)程序開(kāi)發(fā)過(guò)(務(wù)提供者,服務(wù)費(fèi)者,配置文件)

  • 服務(wù)提供者:
  • 1)?????? 定義服務(wù)接口

    2)?????? 定義接口實(shí)現(xiàn)類

    3)?????? Spring配置聲明暴露服務(wù):

    ????

    4)?????? 加載Spring配置

    ?????

  • 服務(wù)消費(fèi)者:
  • 5)?????? Spring配置引用遠(yuǎn)程服務(wù)

    ??????

    6)?????? 加載Spring配置,并調(diào)用遠(yuǎn)程服務(wù)

    u? ClassPathXmlApplicationContext加載配置,然后用getBean方法獲取遠(yuǎn)程代理。

    ?????

    u? 用IOC注入:測(cè)試腳本是用這種方式的。

    ?

    三、??????? Dubbo服務(wù)接口測(cè)試環(huán)境準(zhǔn)備

    1、??? POM.xml引入對(duì)應(yīng)service應(yīng)用jar依賴。

    比如:

    dependency>
    ??? <groupId>com.XXXX.basisdata</groupId>
    ??? <artifactId>basisdata-bankbill-common-facade</artifactId>
    ??? <version>1.1.0</version>
    </dependency>

    2、??? Dubbo服務(wù)spring配置

    u? 由于測(cè)試過(guò)程是遠(yuǎn)程調(diào)用接口的過(guò)程,所以只需要進(jìn)行消費(fèi)方spring配置。

    u? 由于阿里云dubbo應(yīng)用的測(cè)試環(huán)境屬于外網(wǎng),本地機(jī)器需將請(qǐng)求通過(guò)公網(wǎng)機(jī)器的端口轉(zhuǎn)發(fā)給測(cè)試環(huán)境,需要在公網(wǎng)IPTable配置映射。

    u? 沒(méi)有經(jīng)過(guò)注冊(cè)中心,所以不用配置注冊(cè)中心。

    Spring-dubbo配置文件只需對(duì)每個(gè)service如下配置:

    <dubbo:reference interface="com.xxx.xxx.xxx.service.BillDetailService" id="billDetailService" url="dubbo://121.43.177.8:20100" timeout="10000"/> 然后在spring-context.xml加入引入資源配置即可。 <import resource="spring-secret.xml" /> ?

    四、??????? 腳本設(shè)計(jì)結(jié)構(gòu)

  • 創(chuàng)建測(cè)試類公共父類,繼承AbstractTestNGSpringContextTests或者AbstractJUnit4SpringContextTests。
  • 創(chuàng)建測(cè)試類,繼承父類,編寫(xiě)相應(yīng)代碼。
  • ???????

    五、??????? 腳本兩種基本編寫(xiě)方法:

    1、??? 繼承AbstractJUnit4SpringContextTests方法。

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations = {"classpath:/spring-context.xml"})
    @Configuration
    public class BaseJunit4Test extends AbstractJUnit4SpringContextTests {
    } ?

    2、??? 繼承AbstractTestNGSpringContextTests方法。

    @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath:/spring-context.xml"})
    @Configuration
    public class BaseTestNGTest extends AbstractTestNGSpringContextTests {
    } ?????????????? 測(cè)試類繼承BaseTestNGTest即可。

    六、??????? 數(shù)據(jù)驅(qū)動(dòng)兩種基本編寫(xiě)方法:

    1、 基于Junit數(shù)據(jù)驅(qū)動(dòng)。

    u? 父類配置:

    • @RunWith(Parameterized.class)
      @ContextConfiguration(locations = {"classpath:/spring-context.xml"})
      @Configuration
      public class BaseJunit4Test extends AbstractJUnit4SpringContextTests {
      ??? protected TestContextManager testContextManager;
      ??? @Before
      ??? public void setUpContext() throws Exception {
      ??????? this.testContextManager = new TestContextManager(getClass());
      ??????? this.testContextManager.prepareTestInstance(this);
      ??? }
      }

    u? 接口測(cè)試類需編寫(xiě)一個(gè)構(gòu)造類和一個(gè)由@Parameterized.Parameters參數(shù)數(shù)據(jù)方法

    @Parameterized.Parameters
    public static Collection<Integer[]> getTestParameters(){
    //
    //??????? List<Integer[]> list = new ArrayList<Integer[]>();
    //??????? list.add(new Integer[]{2000998248});? //expected,valueOne,valueTwo
    //??????? list.add(new Integer[]{2000020021});
    //??????? list.add(new Integer[]{2001999335});
    //??????? String st=list.toString();
    //??????? System.out.println("list值:" + st);
    //??????? return list;
    //??? }

    List<Integer[]> list = new ArrayList<Integer[]>();

    list? =Arrays.asList(new ??Integer[][]{{2000998248},{2000020021},{2001999335}});
    return list; }
    • 構(gòu)造方法:
    • public TestSelectListByUserId2(Integer userid){
      ??? this.testUser = userid;
      }

    2、 基于TESTNG數(shù)據(jù)驅(qū)動(dòng)。

    u? 父類配置:

    @ContextConfiguration(locations = {"classpath:/spring-context.xml"})
    @Configuration
    public class BaseTestNGTest extends AbstractTestNGSpringContextTests{
    }

    u? 測(cè)試接口類需加一個(gè)由@DataProvider(name = "集合標(biāo)識(shí)")注解的數(shù)據(jù)收集的方法,并將@Test(dataProvider="集合標(biāo)識(shí)")給需要用參數(shù)的測(cè)試方法。

    數(shù)據(jù)收集方法: @DataProvider(name = "testdata") public Object[][] dataprovide()throws IOException{
    System.out.println("dataprovide方法執(zhí)行");
    //??????? return new Object[][]{{2000020013,2},{2001000138,0},{2001000139,2}};
    Object[][] testData =ExcelHandle.readXlsx(excel, "工作表2");
    return testData;
    }

    u? 測(cè)試方法:

    ?????? @Test(dataProvider="testdata")
    public void test_case_1(HashMap<String, String> map) throws Exception {
    operatorUserId=Integer.valueOf(map.get("userId"));
    exceptedvalue =Integer.valueOf(map.get("excepted"));
    ????????//++++++++++++++實(shí)際值+++++++++++++
    Integer actual_value =
    billService.getUserEmailNameCount(operatorUserId);

    //預(yù)期值
    Integer excepted_value =get_excepted_value(operatorUserId);
    //++++++++++++++驗(yàn)證+++++++++++++
    Assert.assertEquals(actual_value,exceptedvalue);
    }

    ?

    轉(zhuǎn)載于:https://www.cnblogs.com/ceshi2016/p/6527210.html

    總結(jié)

    以上是生活随笔為你收集整理的基于Spring开发的DUBBO服务接口测试的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。