You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

gradlew gatlingRun未执行任何测试,请求Gradle-Gatling负载测试解决方案

Gradle-Gatling负载测试未执行问题排查与解决

我来帮你一步步排查并解决这个问题,你的配置里有几个细节需要调整,导致Gatling没找到模拟类所以没执行测试:

1. 修正模拟类的存放路径

Gatling Gradle插件默认的Scala源文件目录是src/gatling/scala,你现在把BasicSimulation.scala放在src/gatling/predictors下,插件会找不到这个类。你需要:

  • 把文件移动到src/gatling/scala/predictors目录下(保持包名predictors不变),这样插件能自动识别到模拟类。

2. 调整Scala版本与插件兼容性

你当前使用的com.github.lkishalmi.gatling插件版本是3.0.2,对应的Gatling核心版本是3.x,而Gatling 3.x不再支持Scala 2.11,需要切换到Scala 2.12版本。修改你的build.gradle中的Scala依赖:

dependencies {
    testCompile 'junit:junit:4.12'
    compile 'org.scala-lang:scala-library:2.12.15' // 换成兼容的2.12版本
}

3. 优化Gatling插件配置

确保你的gatling块配置正确,同时可以显式添加Gatling的核心依赖(插件会自动引入,但显式声明更稳妥),修改后的build.gradle完整配置如下:

plugins { 
    id "com.github.lkishalmi.gatling" version "3.0.2"
    id 'scala' // 用plugins块引入scala插件更规范
}

repositories { 
    mavenCentral() 
}

dependencies {
    testCompile 'junit:junit:4.12'
    compile 'org.scala-lang:scala-library:2.12.15'
    // 显式添加Gatling依赖,确保版本与插件兼容
    gatling 'io.gatling.highcharts:gatling-charts-highcharts:3.0.3'
    gatlingCompile 'io.gatling:gatling-test-framework:3.0.3'
}

gatling {
    simulations = { 
        include "**/predictors/*.scala" // 现在路径正确的话,这个匹配是有效的
    }
}

gatlingRun {
    // 如果endpoint变量未定义,先注释掉这行,等测试跑通后再配置
    // systemProperties 'endpoint': "${endpoint}"
}

4. 验证模拟类的baseURL配置

你的BasicSimulation.scala里用的是http.baseURL("http://localhost:8000/"),而请求路径是api/chemocare/gatling/,拼接后是http://localhost:8000/api/chemocare/gatling/,和你Postman测试的地址一致,这部分没问题,可以保持原样。

做完以上调整后,重新执行gradlew gatlingRun,Gatling应该就能找到并执行你的模拟测试,最后在build/reports/gatling目录下生成测试报告。

内容的提问来源于stack exchange,提问作者Saber Alex

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 07:18:44