background

The company currently features two social networking products for strangers, Nuanchat and CP, both of which are available on Android and iOS. Warm chat covers eight modules of audio and video matching, dating hall, chat room, video live, square, family, IM message and task center, with a total of 841 interfaces; CP covers seven modules of voice room, gift, list, IM message, square, CP Match and Sound Bar, with a total of 548 interfaces. With high product complexity, large team size and fast growth of business data, it is difficult to ensure the stability of product quality simply by “dot dot dot” and “carefulness”.

Question the status quo

  • The test team should support the normal launch of related activities while ensuring the two products to iterate once a week. Under such a background, the quality of the test is not stable, the repeated work is much, and the efficiency declines. For example, every product iteration and activity launch, we need to do the regression of the main process of the whole product and activity, but people always make mistakes and careless, so it is difficult to ensure the continuous and stable output of product and activity quality. Based on this problem, it is urgent to introduce automated testing.

The solution

  • The target

    • In order to reduce the cost of testing labor, improve efficiency, improve the coverage of testing scenarios, improve product quality and improve testing ROI.
  • process

  • Scheme selection

    • Plan a
      • Python Requests + Pytest
    • Scheme 2
      • YAPI + Python Flask
    • Scheme is selected
      • The selection scheme is mainly considered from the following aspects
      1. Reduce the cost and time of tool development and select mature tools or components for secondary development
      2. To reduce the cost of use case entry, test case collections can preferably be added with one click
      3. Increase the use of team members, every student can participate in the interface automation test project
      • After comparing the two schemes and the points under consideration, scheme 2 was finally chosen. YAPI can generate a set of use cases with one click, test case execution is done on YAPI platform, only the execution results are parsed and encapsulated and synchronized to the office cluster, and team members can make assertions on each interface on the platform to complete automated testing
  • design

YAPI part

  • YAPI structures,

    • There is a lot of information about YAPI construction on the web, so I won’t go into details here
  • The test set

    • Create a test set for each application scenario; Take the gift of backpack for example, before and after the gift were adjusted intimate life list, goddess list, the backpack data of the gift-giving party, the integral list interface of the receiving party, and the assertion of the interface response content; See mind mapping

  • assertions

// Define the intimate days list before the gift returns data

// The gift closeness calculation uses the actual value of the user's contribution, and the user's credits are calculated based on the actual value of the gift drawn

var uid = records[1180].body.data.user.id

var arr1 = body.data

var Be_data = records[1187].body.data

var coin = parseInt((records[1190].body.data.coin)/10)


function isInArray(arr,value){

    var arrLength = arr.length

    if(arrLength>0) {for(var i=0; i<arrLength; i++){

            if (value == arr[i].maleUser.id){

                var count = arr[i].count

                count = parseInt(count)

                return count

            }

            if(i == arrLength-1) {return 0}}}else{

        return 0

    }

    

    }



dest_count = isInArray(arr1,uid)



if (Be_data == null){

    assert.equal(count,coin)

}

else{

    var coin = parseInt(records[1190].body.data.coin/10)

    source_count = isInArray(Be_data,uid)

    // If the last daily list intimacy == gift intimacy + initial daily list intimacy, return the verification success, otherwise the last daily list intimacy == gift intimacy + initial daily list intimacy +1

    if (dest_count==source_count+coin){

        assert.equal(1.1)}else{

        assert.equal(dest_count,source_count+coin+1."The closeness after the gift is not equal to the initial closeness plus the closeness of the gift.")}}Copy the code
  • YAPI generates the server test URL

Flask part

  • Code file directory

    • Create blueprint package cp and create blueprint object cp in the __init__ file under the package cp

  • In cp blueprint directory, create views package, create view function, read the server test URL generated by YAPI in YAML file, execute, parse, encapsulate and synchronize the execution result to group chat

  • Store the server test urls for each set of use cases generated by YAPI in a YAML file

  • Routing: urls.py, which provides an interface for operations students

  • Import all the urls needed for the entire project in the init file in step 1

  • Register the cp object in the main entry run.py file

fromCp import cp # Dump the cp object app.register_blueprint(cp,url_prefix) created in the __intit__ file into the cp package='/cp')
Copy the code

The effect

  • Automatic trigger

    - The micro service completes deployment and automatically requests the URL in Flask to execute the set of test cases in YAPICopy the code
  • Interface test passed

  • When an interface error occurs

  • On the YAPI platform, locate the corresponding interface and view the specific response content of the interface

  • performance

    • The automated test covers each microservice, with a total of 125 core interfaces; Module includes video live, family red envelope, audio and video matching, backpack gift, IM message, user chat up, task center, square, lucky bag, chat room, dating hall core application scenarios, a total of 403 interfaces, improve the test coverage.
    • After the introduction of interface automation, the test students will deploy the newly built code into the QA environment. Problems can be exposed before the test students access, reducing the labor cost of the test students; In addition, the automated test can directly view the response content of the interface on the YAPI platform, which can locate the problem more quickly.

conclusion

  • As business complexity increases, incorporating automated testing greatly improves performance and test ROI, as well as the consistent output of product quality

  • The future planning

    • Automatic test can be used as a standard for testing. If the newly deployed code fails the automatic test, it can be directly called back, which indirectly improves the self-testing ability of the development students
    • Automatic access to core scenarios of pre-delivery environment, providing dual guarantee of QA environment and pre-delivery