2

我有这个加特林模拟:

package package_name
import io.gatling.core.Predef._
import io.gatling.http.Predef._

class PerformanceTest extends Simulation {
  private val httpConfiguration = http
    .baseURL(Configuration.baseUrl)
    .acceptEncodingHeader("gzip, deflate")
    .userAgentHeader(Configuration.userAgentName)
    .inferHtmlResources()
    .maxConnectionsPerHostLikeChrome
    .disableClientSharing
    .extraInfoExtractor(dumpSessionOnFailure)
}

其中配置很简单object Configuration { ... }

Gatling 不会编译测试,并说明此错误消息:

[...]\performance-test\src\gatling\scala\package_name\performance\test\PerformanceTest.scala: 
could not find implicit value for parameter configuration: io.gatling.core.config.GatlingConfiguration
  private val httpConfiguration = http
                                  ^
one error found

我该如何解决这个错误?

4

3 回答 3

1

解决方案很简单,令人沮丧:我将包名(不是文件的位置)更改为performance_testcom.company.performance.test之前的)。现在代码编译完美。

于 2018-08-14T06:20:25.960 回答
0

以下代码编译没有错误:

src/test/scala/package_name/PerformanceTest.scala

package package_name

import io.gatling.core.Predef._
import io.gatling.core.session.Expression
import io.gatling.http.Predef._

object Configuration {
  val userAgentName: Expression[String] = "http://computer-database.gatling.io"
  val baseUrl: String = "Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0"
}

class PerformanceTest extends Simulation {
  private val httpConfiguration = http
    .baseURL(Configuration.baseUrl)
    .acceptEncodingHeader("gzip, deflate")
    .userAgentHeader(Configuration.userAgentName)
    .inferHtmlResources()
    .maxConnectionsPerHostLikeChrome
    .disableClientSharing
    .extraInfoExtractor(dumpSessionOnFailure)
}

构建.sbt

name := "gatlingdemo"

version := "0.1"

scalaVersion := "2.12.6"

libraryDependencies += "io.gatling" % "gatling-core" % "2.3.1"
libraryDependencies += "io.gatling" % "gatling-http" % "2.3.1"

这是一个快速入门:https ://gatling.io/docs/2.3/quickstart/#gatling-scenario-explained

其中配置很简单object Configuration {}

Configuration不能只是object Configuration {},它应该包含userAgentNameand baseUrl

于 2018-08-13T13:59:11.817 回答
0

就我而言,我在模拟类中定义了如下变量

val configuration = ConfigFactory.load()..

导致问题的原因...具有相同的消息

于 2019-08-23T15:44:40.303 回答