实践Dubbo单元测试

把dubbo服务作为spring bean来测试,例如:

1
2
3
4
5
6
7
8
9
10
11
12
13
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {DubboRegistryZooKeeperProviderBootstrap.class})
public class TestRemoteServiceImplTests1 {

    @Autowired
    private TestRemoteService testRemoteService;

    @Test
    public void test1() {
        ApiResult apiResult = testRemoteService.test("abc");
        Assert.assertEquals("OK", apiResult.getStatus().name());
    }
}

把dubbo服务通过远程调用来测试,例如:

1
2
3
4
5
6
7
8
9
10
11
12
13
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {DubboRegistryZooKeeperProviderBootstrap.class})
public class TestRemoteServiceImplTests {
    
    @Reference
    private TestRemoteService testRemoteService;

    @Test
    public void test1() {
        ApiResult apiResult = testRemoteService.test("abc");
        Assert.assertEquals("OK", apiResult.getStatus().name());
    }
}