You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2021/04/17 07:44:41 UTC

[GitHub] [servicecomb-java-chassis] zhufeizzz opened a new issue #2353: ServiceComb怎么配合SpringBootTest进行UT测试的?

zhufeizzz opened a new issue #2353:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2353


   我们计划是用SpringBootTest方式启动本微服务,并通过UT代码调用微服务自身CSE接口进行测试
   ```
   @SpringBootTest(classes = ScheduleJobApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
   class TimerTaskSchedulerTest {
   }
   ```
   遇到几个问题:
   1、如何指定HTTP端口,因为UT需要并发执行,理论上需要使用SpringBoot的RandomPort。那CSE如何启动?需要代码中动态获取随机端口好进行设置吗?
   2、当有多个实例启动时,如何保证CSE会调用到本节点?
   3、这种方式是不是标准的CSE UT写法,官方推荐如何进行?我看了你写的文档:https://github.com/apache/servicecomb-java-chassis/issues/1498。我们还是想以JUnit本地运行的方式测试,而不是部署到Docker进行远程调用测试。
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] zhufeizzz commented on issue #2353: ServiceComb怎么配合SpringBootTest进行UT测试的?

Posted by GitBox <gi...@apache.org>.
zhufeizzz commented on issue #2353:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2353#issuecomment-822128906


   @liubao68 我知道固定端口是用如下方式配置,如果是SpringBootTest随机端口有配置指导吗?
   ```
   servicecomb:
     rest:
       address: 0.0.0.0:8080
   server:
     port: 8080
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] liubao68 edited a comment on issue #2353: ServiceComb怎么配合SpringBootTest进行UT测试的?

Posted by GitBox <gi...@apache.org>.
liubao68 edited a comment on issue #2353:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2353#issuecomment-822892452


   ```
   server:
     port: 0
   ```
   
   不过注册就读取不到实际的地址了。 UT的话感觉一般不需要注册。 如果需要注册,暂时也想不到什么办法。 
   
   参考:https://www.baeldung.com/spring-boot-running-port


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] liubao68 commented on issue #2353: ServiceComb怎么配合SpringBootTest进行UT测试的?

Posted by GitBox <gi...@apache.org>.
liubao68 commented on issue #2353:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2353#issuecomment-822106335


   servicecomb默认提供的模式不依赖spring boot, 因此你无法直接使用spring boot test来进行测试。 详细说明参考:
    1. [多协议介绍](https://docs.servicecomb.io/java-chassis/zh_CN/transports/introduction/)
    2. [Servlet模式介绍和Spring Boot集成方式介绍](https://docs.servicecomb.io/java-chassis/zh_CN/transports/rest-over-servlet/)
   
   如果使用spring boot test, 只能使用Spring Boot集成方式。 那么servicecomb就是一个spring boot应用,和普通的spring boot应用并没有任何差别,监听的也是SpringBoot的随机端口。 servicecomb只是作为spring boot运行容器里面的一个servlet。 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] liubao68 commented on issue #2353: ServiceComb怎么配合SpringBootTest进行UT测试的?

Posted by GitBox <gi...@apache.org>.
liubao68 commented on issue #2353:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2353#issuecomment-822892452


   ```
   server:
     port: 0
   ```
   
   不过注册就读取不到实际的地址了。 UT的话感觉一般不需要注册。 如果需要注册,暂时也想不到什么办法。 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [servicecomb-java-chassis] zhufeizzz commented on issue #2353: ServiceComb怎么配合SpringBootTest进行UT测试的?

Posted by GitBox <gi...@apache.org>.
zhufeizzz commented on issue #2353:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2353#issuecomment-822992803


   > ```
   > server:
   >   port: 0
   > ```
   > 
   > 不过注册就读取不到实际的地址了。 UT的话感觉一般不需要注册。 如果需要注册,暂时也想不到什么办法。
   > 
   > 参考:https://www.baeldung.com/spring-boot-running-port
   
   那能不能理解为目前ServiceComb不支持通过UT进行接口测试?必须通过启动服务+外置客户端的方式进行测试?如果这样的话编写测试用例的成本大幅上升。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org