Software testing/test development丨Interface testing study notes sharing

1. Mock test

1. Mock test scenario

  1. Front-end and back-end data interaction
  2. Third-party system data interaction
  3. Hardware device decoupling

image

2. The value and significance of Mock testing

  1. No reliance on third-party data
  2. Save work
  3. Save joint debugging

3. Mock core elements

  1. Matching rules: mock interface, which interfaces to change, and where is the data in the interface?
  2. Analog response

4. Mock actual combat

(1) Rewrite principle

image

  1. Scenario example
  • Modify the stock name on the Snowball Quotation Page
  • Modify the stock price on the Snowball Quotes page
  1. Setting method
  • Tools -> Rewrite
  • Check Enable Rewrite
  • Click the Add button below to create a new rewritten rule
  • Edit the rewrite rule on the right
  • Click OK to take effect

image

(2) Map Local principle

image

  1. Scenario example
  • Modify the stock name on the Snowball Quotation Page
  • Modify the stock price on the Snowball Quotes page
  1. operate
  • Prepare local interface response data
  • Configure Map Local
    • Select the interface for Map Local
    • Right mouse button – select the Map Local option to enter the setting interface
    • Map From fill in the interface information
    • Map To select local file
  • Modify Map Local configuration: Tools – Map Local
(3) Map Remote principle

image

  1. Scenario example
  1. operate
  • Select the interface, right-click the mouse, and select Map Remote to enter the settings page.
  • Set redirected interface information
  • Click OK to take effect
  • Modify settings: Tools – Map Remote. Find the corresponding interface and double-click to enter the modification interface.

image

2. Mock technology system

1. The value and significance of Mock

  • Increase testing depth
  • Improve testing efficiency
  • cut costs

2. Test Double test double

  • Test Double official website: TestDouble
  • Dummy placeholder  object is passed but never actually used. Usually they are used only to populate parameter lists.
  • Fake  objects actually have working implementations, but often take some shortcuts that make them unsuitable for production (in-memory databases are a good example).
  • Stubs objects  provide canned answers to calls during testing and typically do not respond at all to anything outside of the test program.
  • Spies spy objects  They also log some information based on how they are called. One form of this might be an email service that logs how many messages are sent.
  • Mocks Mock objects  are what we're talking about here: pre-programmed objects whose expectations form the specification of the calls they expect to receive.

3. Test the differences between key concepts of avatars

concept Listen for calls default expectations Preset expectations on demand real data Real data modification
Dummy puppet object
Spy spy object
Fake fake object
Stub pile object
Mock simulation object

4. Technical architecture examples

  • dummy as long as the port is open
  • fake in-memory database
  • spy UI interface backend request record
  • stub fake login backend service
  • Hook new user judgment method modification
  • proxy proxy forwarding mechanism
  • mock mock object

image

5. Fake false object definition

Fake objects actually have working implementations, but often take some shortcuts that make them unsuitable for production (pure in-memory databases are a good example).

image

6. Fake application scenarios

image

7. Stub pile definition

Provides canned answers to calls made during testing and often does not respond at all to anything outside of the test procedure.

image

8. Stub application scenario Swagger

image

9. Mock simulation object definition

Mocks are preprogrammed with expectations that form the specification of the calls they expect to receive. If they receive calls they are not expecting, they can throw an exception and check during validation to make sure they are getting all the calls they expected.

image

10. Two application scenarios of Mock

  • mock on stub: return expected data on demand
  • mock on proxy: return a modified copy of the real data on demand

11. Commonly used Mock tools

  • Charles is commonly used by test engineers
  • BurpSuite commonly used by hackers
  • Fiddler can only be used on Windows
  • Nginx server reverse proxy and modification
  • Mitmproxy proxy tool programmable
  • Wiremock proxy tool programmable

12、 mitmproxy

  • Official website: mitmproxy.org/
  • mitmproxy is a set of tools that provide interactive, SSL/TLS-enabled interception proxies for HTTP/1, HTTP/2, and WebSockets.

image

13. mitmproxy’s powerful plug-in mechanism Addons

  • dns
  • tcp
  • cert
  • http/https
  • websocket

image

14. adb mock case

import sys

from mitmproxy import ctx
from mitmproxy import tcp
from mitmproxy.utils import strutils
from mitmproxy.tools.main import mitmdump


def tcp_message(flow: tcp.TCPFlow):
    message = flow.messages[-1]
    old_content = message.content
    message.content = old_content.replace(
        b":0;localabstract:webview_devtools_remote_",
        b":   0;localabstract:xweb_devtools_remote_"
    )

    ctx.log.info(
        "[tcp_message{}] from {} to {}:\n{}".format(
            " (modified)" if message.content != old_content else "",
            "client" if message.from_client else "server",
            "server" if message.from_client else "client",
            strutils.bytes_to_escaped_str(message.content))
    )


if __name__ == '__main__':
    sys.argv = ["", "-p", "5038", "--rawtcp", "--mode", "reverse:http://localhost:5037/", "-s", sys.argv[0], "-vv"]
    mitmdump()

15、 WireMock

  • Official website: wiremock.org/
  • Flexible tool for building mock APIs. Create a stable development environment, isolate yourself from wacky third parties, and mock APIs that don't exist yet.

3. Mock tools and customization

1. Introduction to Mitmproxy

  • mitmproxy: interactive command line tool

    • Note: Windows is not supported
  • mitmweb: browser-based interface interaction tool

  • mitmdump: simple terminal output, you can write powerful plug-ins and scripts

  • Official website: mitmproxy.org/

2. Mitmproxy installation

  • It is recommended to use python for installation
// 方式一
pip install mitmproxy==5.2.0

// 方式二
pip install pipx
pipx install mitmproxy==5.2.0

// 验证是否安装成功
mitmdump --version

3. PC side certificate configuration

  • Configure computer agent
  • Start mitmproxy
  • Enter the address mitm.it in the browser
  • Select the corresponding system to download the certificate and install it

image

4. Mobile certificate configuration

  • Configure the proxy on the mobile phone, configure the ip to the ip address of the computer , and configure the port to the mitmproxy listening port
  • Start mitmproxy
  • Enter the address mitm.it in your mobile browser
  • Select Android, download and install, and you can successfully capture the https data packet on the mobile phone.

5. Introduction to mitmdump parameters

  • -p Parameter, specify the listening port, the default listening port is 8080
  • -s Parameters, execute python script

6. Core components

Finally, I would like to thank everyone who reads my article carefully. Reciprocity is always necessary. Although it is not a very valuable thing, if you can use it, you can take it directly:

This information should be the most comprehensive and complete preparation warehouse for [software testing] friends. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey. I hope it can also help you! 

Guess you like

Origin blog.csdn.net/2301_78276982/article/details/135269904