All Products
Search
Document Center

:Use Alibaba Cloud Toolkit to test microservices

Last Updated:Nov 25, 2024

In a microservices architecture, service testing faces an increasing number of challenges. You can configure an on-premises registry so that you can use Alibaba Cloud Toolkit to test microservices. Alibaba Cloud Toolkit allows you to test microservices in the High-speed Service Framework (HSF) and Apache Dubbo frameworks. The feature of testing microservices in the Spring Cloud framework is being developed.

Prerequisites

Before you use Alibaba Cloud Toolkit to test microservices, make sure that the following operations are complete:

Configure and start a registry

Configure a registry for the provider application and the consumer application, respectively.

Start a local registry for a provider application

  1. Open a provider project in IntelliJ IDEA.

  2. In the top navigation bar of IntelliJ IDEA, choose File > Settings.

  3. In the Settings dialog box, choose Alibaba Cloud Toolkit > Microservice > Microservice.

  4. On the registry configuration page, select Use Local Registry, select a registry type, and then click Start.

    After the configuration is complete, Local registry started appears in the Local Registry dialog box.

Configure a custom registry for a consumer application

  1. Open a consumer project in IntelliJ IDEA.

  2. In the top navigation bar of IntelliJ IDEA, choose File > Settings.

  3. In the Settings dialog box, choose Alibaba Cloud Toolkit > Microservice > Microservice.

  4. On the registry configuration page, select Join Self-managed Nacos Registry, enter the IP address of the registry in the text box, and then click OK.

Test microservices

This section describes how to test microservices. A Dubbo microservice is used in the example. The procedure for testing HSF microservices is the same as that for testing Dubbo microservices.

  1. Extract the Dubbo interface as a project or a subproject. Then, test the microservice in this interface project.

  2. Open the interface file in the interface project. Right-click the interface name and choose Alibaba Cloud > Microservice Tools > Test.

  3. In the Microservice Test dialog box, configure the parameters for testing and click Start to Test.

    Parameter

    Description

    Registry

    After you select Join Custom Registry on the registry configuration page, the registry information is automatically entered. If the registry is not configured, you must enter the address of the registry in the IP address:Port format, such as 127.0.0.1:8080.

    Service Type

    Select the type of your microservice framework from the drop-down list. Valid values: DUBBO and HSF. The feature of testing microservices in the Spring Cloud framework is being developed.

    Service Version

    In the address bar of your browser, enter http://localhost:8080/. In the left-side navigation pane, choose Service Management > Services. Then, view the microservice version in the microservice name. For example, if the service name is providers:com.dubbo.example.DemoService:1.0.0:dubbo, the microservice version is 1.0.0.

    Service Group

    In the address bar of your browser, enter http://localhost:8080/. In the left-side navigation pane, choose Service Management > Services. Then, view the microservice group in the microservice name. For example, if the service name is providers:com.dubbo.example.DemoService:1.0.0:dubbo, the microservice group is dubbo.

    Code Editor of Test Command

    • The sample code snippet in the test command briefly describes how to obtain the microservices. You cannot edit or modify the sample code snippet.

    • In the section for editing custom code, you can enter custom code for testing. The following code provides an example:

      String hello = demoservice.sayHello("edas");
      System.out.println(hello);

Result

The system automatically performs the following operations:

  1. Compile the current project.编译当前工程

  2. Open the terminal to perform a test task.在终端执行测试任务

    The test code and the relevant dependencies are generated in the .edas/service-test/dubbo-test directory in the home directory. If the compilation fails, you can view the test code in the .edas/service-test/dubbo-test directory.

    查看测试代码