课程答疑帖
参考资料
演练的源代码:https://github.com/seveniruby/RestAssuredDemoOffline2
作业1
- 本地搭建swagger editor
- 生成python或者java的client
- 打包为lib
- 在自己的测试项目中调用lib进行单元测试
- 把自己的测试用例代码贴到帖子里(不用截图)
作业2
添加依赖
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.6.1</version>
</dependency>
外网同学也可以调用
consumer.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="seveniruby-demo-consumer"/>
<dubbo:registry address="101.132.159.87:9090"/>
<dubbo:reference id="demoService" interface="DemoService"/>
</beans>
接口定义
public interface DemoService {
String sayHello(String name);
}
测试用例
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.junit.Assert.*;
public class DubboTest {
public static DemoService demoService;
@BeforeClass
public static void setup(){
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
new String[]{"dubbo/consumer.xml"});
context.start();
demoService = (DemoService) context.getBean("demoService");
}
@Test
public void testHelloWorld(){
assertEquals(demoService.sayHello(""), "Hello ");
assertEquals(demoService.sayHello("World"), "Hello World");
}
@Test
public void testHelloSeveniruby(){
assertEquals(demoService.sayHello("seveniruby"), "Hello Seveniruby");
}
}