java微服务测试_测试Java微服务:不是大问题吗?

java微服务测试

对于经常在网上阅读文章的开发人员来说,许多组织都希望从当前的整体Java应用程序应用程序迁移(或扩充),这不足为奇。 对与错,微服务架构已经成为实现基于Web的应用程序的事实上的最佳样式。 但是,微服务提供的“巨大力量”带来了巨大的责任和挑战。

确实,关于实现基于微服务的体系结构 ,对数据建模以及运营 (和组织)方面的挑战已经写了很多文章。 但是,除了Toby Clemson的出色文章“微服务体系结构中的测试策略 ”外,关于用这种新的体系结构样式进行测试所面临的挑战的文献很少。 本文旨在增加有关测试基于Java的微服务的讨论。

作为我与SpectoLabsOpenCredo一起工作的一部分,我们已帮助多个组织构建和部署基于微服务的应用程序,包括绿地原型,棕地集成和迁移。 我们在此过程中学到了很多东西,今天我们渴望分享我们在如何设计,构建和测试基于微服务的系统方面的发现:

设计系统:确定服务边界

  1. 确定现有(或新)系统中业务功能的范围。 我们通常将这些领域定义为领域驱动设计(DDD)有限上下文 ”。
  2. 此步骤可能需要一些时间(并且还将是迭代的),但是输出通常是一个上下文映射 ,该上下文映射表示定义应用程序服务边界时的第一遍。

设计服务API:确定服务功能

  1. 与相关的企业所有者,领域专家和开发团队合作,以定义服务功能和API。
  2. 使用行为驱动设计(BDD)技术的“ 三个朋友 ”。
  3. 此步骤的典型输出包括:
    • 一系列BDD样式的验收测试,它们声明组件(单个微服务)级别的要求,例如Cucumber Gherkin语法验收测试脚本;
    • 测试脚本将针对的API规范,例如SwaggerRAML文件。

由内而外建立服务

  1. 现在我们有了我们的API规范和相关的(服务级别)业务需求,我们可以开始从内而外构建服务功能!
  2. 继Toby Clemson撰写的关于微服务测试的出色文章之后,我们在这里同时使用集成测试和单元测试(社交测试和单独测试),并且经常使用双循环TDD方法。
  3. 我们经常使用JUnitLambda-behaveMockitoHoverfly Java进行基础单元测试。

组件测试

  1. 结合从内到外构建服务,我们还致力于组件级测试。 这与上面提到的集成测试不同,因为组件测试通过公共API运行,并测试整个业务功能。
  2. 通常,第一波组件测试使用我们在2.3中定义的验收测试脚本,并且这些脚本断言我们已经在此服务中正确实现了业务功能。
  3. 我们在这里喜欢的工具包括REST保证的Spring Boot测试功能
  4. 测试非功能需求(NFR)。 示例包括:

合同测试–验证组件交互

  1. 验证组件之间建议的交互。
  2. 在微服务领域中,一种流行的方法是使用消费者驱动的合同 ,并且可以使用诸如Spring Cloud ContractPact-JVMPacto之类的框架来实现。

端到端(E2E)测试:声明系统级业务功能和NFR

  • E2E自动化测试从本质上断言了核心用户旅程和应用程序功能(并还防止了退化)。
  • 测试非功能性/跨功能性需求,例如,断言所有关键业务流程都在工作,在一定时间内做出响应并且是安全的。
  • 当E2E测试不可用的触摸系统时,请使用Hoverfly之类的工具来模拟API。 可以通过Hoverfly中间件注入延迟或失败。
  • 该过程的此步骤的输出应包括:
    • 一个功能正常且功能强大的系统;
    • 系统的自动验证;
    • 客户满意!

最后的话

如果您喜欢阅读本文,那么可以在specto.io上找到更全面的版本:“ 设计,构建和测试微服务的建议食谱 ”。

eclipseorb_color

该文章最初发表于2017年1月的Eclipse Newsletter:Exploring New Technologies

有关更多信息和文章,请查阅Eclipse Newsletter

Daniel Bryant博士将在JAX DevOps上发表两个演讲:

翻译自: https://jaxenter.com/testing-java-microservices-not-big-problem-131651.html

java微服务测试

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Summary Testing Java Microservices teaches you to implement unit and integration tests for microservice systems running on the JVM. You'll work with a microservice environment built using Java EE, WildFly Swarm, and Docker. You'll learn how to increase your test coverage and productivity, and gain confidence that your system will work as you expect. Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications. About the Technology Microservice applications present special testing challenges. Even simple services need to handle unpredictable loads, and distributed message-based designs pose unique security and performance concerns. These challenges increase when you throw in asynchronous communication and containers. About the Book Testing Java Microservices teaches you to implement unit and integration tests for microservice systems running on the JVM. You'll work with a microservice environment built using Java EE, WildFly Swarm, and Docker. You'll advance from writing simple unit tests for individual services to more-advanced practices like chaos or integration tests. As you move towards a continuous-delivery pipeline, you'll also master live system testing using technologies like the Arquillian, Wiremock, and Mockito frameworks, along with techniques like contract testing and over-the-wire service virtualization. Master these microservice-specific practices and tools and you'll greatly increase your test coverage and productivity, and gain confidence that your system will work as you expect. What's Inside Test automation Integration testing microservice systems Testing container-centric systems Service virtualization About the Reader Written for Java developers familiar with Java EE, EE4J, Spring, or Spring Boot. About the Authors Alex Soto Bueno and Jason Porter are Arquillian team members. Andy Gumbrecht is an Apache TomEE developer and PMC. They all have extensive enterprise-testing experience. Table of Cont
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值