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:
IntelliJ IDEA V2018.3 or later is installed.
Alibaba Cloud Toolkit is installed and configured in IntelliJ IDEA. For more information, see Install and configure Alibaba Cloud Toolkit in IntelliJ IDEA.
ImportantYou must use Alibaba Cloud Toolkit V2020.4.1 or later.
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
Open a provider project in IntelliJ IDEA.
In the top navigation bar of IntelliJ IDEA, choose .
In the Settings dialog box, choose .
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
Open a consumer project in IntelliJ IDEA.
In the top navigation bar of IntelliJ IDEA, choose .
In the Settings dialog box, choose .
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.
Extract the Dubbo interface as a project or a subproject. Then, test the microservice in this interface project.
Open the interface file in the interface project. Right-click the interface name and choose .
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
. 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
. 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:
Compile the current project.
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.