In a microservices model, 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 microservice applications in High-Speed Service Framework (HSF) and the Apache Dubbo framework. The feature of testing microservice applications in the Spring Cloud framework is being developed.

Prerequisites

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

Configure and start a registry

Separately configure a registry for provider and consumer applications.
Note You can use Alibaba Cloud Toolkit to configure a registry. You can also start a light-weight configuration center in an on-premises environment. For more information, see Start the light-weight configuration registry. Assume that you use a standalone instance to configure the light-weight configuration center. In this case, when you view information about a service version and a service group in Step3, enter http://<IP address of the instance>:8080.

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 left-side navigation pane of the Settings page, choose Alibaba Cloud Toolkit > EDAS.
  4. On the registry configuration page, select Use Local Registry and click Start Now.
    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 left-side navigation pane of the Settings page, choose Alibaba Cloud Toolkit > EDAS.
  4. On the registry configuration page, select Join Custom Registry. In the field on the right side, enter the IP address of the registry, and then click OK.

Test microservices

The procedure for testing HSF microservices is the same as that for testing Dubbo microservices. In this example, a Dubbo microservice is tested.

  1. Extract 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. Select the interface, right-click the interface, and then choose Alibaba Cloud > Microservice Tools > Test in the shortcut menu.
  3. In the Microservice Test dialog box, specify parameters for testing, and click Start to Test.
    Parameter Description
    Registry After you select Join Custom Registry on the registry management page, the system automatically fills in registry information. If the registry is not configured, you must enter the address of the registry in the IP address:Port format, for example, 127.0.0.1:8080.
    Service Type Select the type of your microservice framework in 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 service version in the service name. For example, if the service name is providers:com.dubbo.example.DemoService:1.0.0:dubbo, the service 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 service group in the service name. For example, if the service name is providers:com.dubbo.example.DemoService:1.0.0:dubbo, the service group is dubbo.
    Code Editor of Test Command
    • The sample code snippet in the test command briefly describes how to obtain the Interface service. You cannot edit or modify the sample code snippet.
    • In the section for editing custom code, you can enter custom test code for testing. The following code provides an example of custom code:
      String hello = demoservice.sayHello("edas");
      System.out.println(hello);

Result

The system automatically completes 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 go to this directory to view the test code.

    View the test code