In a microservice architecture, service testing faces an increasing number of challenges. You can configure a local 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

Separately configure a registry for a provider application and a consumer application.
Note You can use Alibaba Cloud Toolkit to configure a registry. You can also start a lightweight configuration center in an on-premises environment. For more information, see Start the light-weight configuration registry. You may use a standalone instance to configure the lightweight configuration center. In this case, enter http://<IP address of the instance>:8080 in Step 3 to view the microservice version and microservice group.

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 to be used in the text box, and then click OK.

Test microservices

This section uses a Dubbo microservice as an example to describe how to test microservices. 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 and choose Alibaba Cloud > Microservice Tools > Test in the shortcut menu.
  3. In the Microservice Test dialog box, set 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 are only DUBBO and HSF. 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 microservice 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 microservice 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 microservice. 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. Compile the current project
  2. Open the terminal to perform a test task. Perform a test task at the terminal

    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.

    View the test code