我有这个加特林模拟:
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
如何解决此错误?
答案 0 :(得分:2)
解决方案很简单,令人沮丧:我将软件包名称(而不是文件的位置)更改为performance_test
(之前是com.company.performance.test
)。现在,代码可以完美地编译。
答案 1 :(得分:1)
下面的代码编译没有错误:
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)
}
build.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 {}
,它应包含userAgentName
和baseUrl
。
答案 2 :(得分:0)
在我的情况下,我在模拟类中定义了以下变量
val configuration = ConfigFactory.load()..
导致问题的原因...消息相同