什么是微服务回归套件的最佳方法,Scala 可以用于此吗?

What could be best approach for regression suite for microservices, Can Scala be used for that?

我被要求准备一个用于测试微服务的回归套件,为此我需要: - 运行 个脚本 - 运行 不同的 API(对于下一个 API 中使用的场景可以是多个) - 以某种可呈现的格式发布结果

我自己的第一选择是 Jmeter,但高级资源不同意,我被要求使用 SCALA,在使用 Scalatest 时,我坚持使用 Futures,因为我的大部分测试都围绕着调用 Restful API 的。

我仍然认为 Jmeter 更适合我正在做的事情,但是没有坚实的基础,有人可以建议我应该选择哪一个吗?

当然可以,我正在为 , , and 我的微服务使用 scalatest。

没怎么用过 JMeter,我试过用它来对我的微服务进行性能测试,对我来说有点沮丧,立即放弃了。

Scalatest 对我来说 f#*$_&g 很有成效。

一个非常简单的集成测试示例,(我使用 https://jsonplaceholder.typicode.com/posts/1 作为我的 API 在线端点 API)

class SomeHttpFlowSpecs extends HttpFlowSpecs {

  feature("Getting user posts on my API server") {

    scenario("As a software engineer, I want to receive the user posts when I call the endpoint") {

      When("I send a GET request to the http endpoint")
      val response = doHttpGet("https://jsonplaceholder.typicode.com/posts/1")

      Then("I receive 200 response back with the user posts")
      assert(response.getStatusLine.getStatusCode == 200)

      val expectedJson =
        """
          |{
          |  "userId": 1,
          |  "id": 1,
          |  "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
          |  "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
          |}
        """.stripMargin

      assert(JSON.parseRaw(responseContent(response)) == JSON.parseRaw(expectedJson))
    }
  }
}

我自己写了 HttpFlowSpecs 作为一个 Util 来进行 http 调用和处理响应。与您所说的 Future 响应不同,这些呼叫对我来说是同步的。我正在使用众所周知的 apache httpclient 进行 http 通信。

class HttpFlowSpecs extends extends FeatureSpec with GivenWhenThen with BeforeAndAfterAll {

  def doHttpGet(endpoint: String): CloseableHttpResponse = {
    val httpRequest = new HttpGet(endpoint)
    val response = (new DefaultHttpClient).execute(httpRequest)
    response
  }

  def doHttpPost(endpoint: String, content: String, contentType: String = "application/json"): CloseableHttpResponse = {
    val httpRequest = new HttpPost(endpoint)
    httpRequest.setHeader("Content-type", contentType)
    httpRequest.setEntity(new StringEntity(content))

    val response = (new DefaultHttpClient).execute(httpRequest)
    response
  }

  def responseContent(response: CloseableHttpResponse): String = {
    val responseBody: String = new BufferedReader(new InputStreamReader(response.getEntity.getContent))
      .lines().collect(Collectors.joining("\n"))

    println("Response body = " + responseBody)
    responseBody
  }
}

这是我用于测试的非常简单的 conifers-spec

我将 pegdown - Java Markdown processor 与 scalatest 一起用于 html 报告,如下所示,

此外,您可以以非常易读的格式查看所有场景,请参阅我的项目中的一个组件测试

我如何运行 我的测试

mvn clean test

希望这有用,如果有任何问题,请告诉我,我们很乐意提供帮助。

我宁愿选择 JMeter,主要特点是:

  • 开箱即用(采样器、pre/post 处理器、断言、reporting 等)
  • JMeter 测试可以在多台机器上 scaled 到 运行
  • 可以使用 GUI 创建 JMeter 测试,无需编程语言知识

还有Gatling tool where tests are being created using Scala-based DSL, however according to Open Source Load Testing Tools: Which One Should You Use?JMeter在协议支持、可扩展性和吞吐量方面更好