DubboTest dubbo接口测试示例代码

import org.apache.dubbo.demo.DemoService;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.startsWith;

public class DubboTest {
    static DemoService demoService;

    @BeforeAll
    static void beforeAll() {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-consumer.xml");
        context.start();
        demoService = context.getBean("demoService", DemoService.class);
    }

    @Test
    void sayHello() {
        String res;
        res = demoService.sayHello("seveniruby");
        System.out.println(res);
        assertThat(res, startsWith("Hello seveniruby"));

        res = demoService.sayHello("ceshiren.com");
        System.out.println(res);
        assertThat(res, startsWith("Hello ceshiren.com"));
    }
}