Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
660 views
in Technique[技术] by (71.8m points)

How to run Karate and Gatling with Gradle build system

I'm trying to run a Karate test as a Gatling performance test. My entire setup works perfect when using Maven. I am being forced to use Gradle however. When trying to run under Gradle the below disaster unfolds.

Appreciate any ideas what might be causing KarateAction to crash.

MyAPI.scala

class MyAPI extends Simulation {
    val protocol = karateProtocol(
        "/myendpoint" -> Nil
    )

    val action = karateFeature("classpath:org/mycompany/karate/tests/myAPI.feature@test=myTag")

    setUp(
        scenario("my-api")
            .exec(action)
            .inject(rampUsersPerSec(1) to (5) during (5 seconds))
            .protocols(protocol)
    )
}

build.gradle

buildscript {
    ext {
        karateVersion = '0.9.2'
    }
}

apply plugin: 'scala'

configurations {
    gatling
}

dependencies {
    testCompile("com.intuit.karate:karate-apache:${karateVersion}")
    testCompile("com.intuit.karate:karate-mock-servlet:${karateVersion}")
    testCompile("com.intuit.karate:karate-junit4:${karateVersion}")
    testCompile("com.intuit.karate:karate-gatling:${karateVersion}")
    testCompile("net.masterthought:cucumber-reporting:3.8.0")

    gatling "org.scala-lang:scala-library:2.12.8"
    gatling "io.gatling:gatling-app:3.0.2"
    gatling "io.gatling.highcharts:gatling-charts-highcharts:3.0.2"
    gatling "com.intuit.karate:karate-gatling:${karateVersion}"
}

sourceSets {
    simulations {
        scala {
            srcDirs = ['src/test/java/org/mycompany/karate/perf']
        }
        resources {
            srcDirs = ['src/test/java/org/mycompany/karate/perf']
        }

        compileClasspath += configurations.gatling
    }
    test {
        resources {
            srcDir file('src/test/java')
            exclude '**/*.java'
        }
    }
}

test {
    systemProperty "karate.options", System.properties.getProperty("karate.options")
    systemProperty "karate.env", System.properties.getProperty("karate.env")
    outputs.upToDateWhen { false }
}

task gatlingRun(type: JavaExec) {
    description = 'Run Gatling Tests'
    new File("${buildDir}/reports/gatling").mkdirs()

    classpath = sourceSets.simulations.runtimeClasspath += configurations.gatling

    main = "io.gatling.app.Gatling"
    args = [
        '-s', 'org.mycompany.karate.perf.MyAPI',
        '-sf', 'src/test/java/org/mycompany/karate/perf',
        '-rf', "${buildDir}/reports/gatling"
    ]
    systemProperties System.properties
}

command line

gradle gatlingRun

command line output

> Task :compileSimulationsJava NO-SOURCE

> Task :compileSimulationsScala
Pruning sources from previous analysis, due to incompatible CompileSetup.
there were 6 feature warnings; re-run with -feature for details
one warning found

> Task :processSimulationsResources NO-SOURCE
> Task :simulationsClasses

> Task :gatlingRun
16:40:27.238 [main] INFO io.gatling.core.config.GatlingConfiguration$ - Gatling will try to use 'gatling.conf' as custom config file.
16:40:27.598 [GatlingSystem-akka.actor.default-dispatcher-3] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started
16:40:28.242 [GatlingSystem-akka.actor.default-dispatcher-3] INFO io.gatling.core.stats.writer.ConsoleDataWriter - Initializing
16:40:28.242 [GatlingSystem-akka.actor.default-dispatcher-4] INFO io.gatling.core.stats.writer.LogFileDataWriter - Initializing
16:40:28.248 [GatlingSystem-akka.actor.default-dispatcher-3] INFO io.gatling.core.stats.writer.ConsoleDataWriter - Initialized
16:40:28.253 [GatlingSystem-akka.actor.default-dispatcher-4] INFO io.gatling.core.stats.writer.LogFileDataWriter - Initialized
Simulation org.mycompany.karate.perf.MyAPI started...
16:40:28.359 [GatlingSystem-akka.actor.default-dispatcher-2] ERROR com.intuit.karate.gatling.KarateAction - 'classpath:org/mycompany/karate/tests/myAPI.feature@test=myTag' crashed on session Session(my-api,1,1558395628341,Map(),0,OK,List(),io.gatling.core.protocol.ProtocolComponentsRegistry$$Lambda$329/1759250827@7cee98de), forwarding to the next one
java.lang.NullPointerException: null
        at com.intuit.karate.Resource.<init>(Resource.java:55)
        at com.intuit.karate.core.FeatureParser.parse(FeatureParser.java:75)
        at com.intuit.karate.FileUtils.parseFeatureAndCallTag(FileUtils.java:155)
        at com.intuit.karate.Runner.callAsync(Runner.java:183)
        at com.intuit.karate.gatling.KarateAction.execute(KarateAction.scala:77)
        at io.gatling.core.action.Action.$bang(Action.scala:38)
        at io.gatling.core.action.Action.$bang$(Action.scala:38)
        at com.intuit.karate.gatling.KarateAction.io$gatling$core$action$ChainableAction$$super$$bang(KarateAction.scala:37)
        at io.gatling.core.action.ChainableAction.$bang(Action.scala:63)
        at io.gatling.core.action.ChainableAction.$bang$(Action.scala:61)
        at com.intuit.karate.gatling.KarateAction.io$gatling$core$action$ExitableAction$$super$$bang(KarateAction.scala:37)
        at io.gatling.core.action.ExitableAction.$bang(BlockExit.scala:138)
        at io.gatling.core.action.ExitableAction.$bang$(BlockExit.scala:136)
        at com.intuit.karate.gatling.KarateAction.$bang(KarateAction.scala:37)
        at io.gatling.core.controller.inject.Workload.startUser(Workload.scala:55)
        at io.gatling.core.controller.inject.Workload.injectUser(Workload.scala:64)
        at io.gatling.core.controller.inject.open.OpenWorkload.$anonfun$injectBatch$1(OpenWorkload.scala:35)
        at io.gatling.core.controller.inject.open.OpenWorkload.$anonfun$injectBatch$1$adapted(OpenWorkload.scala:35)
        at io.gatling.core.controller.inject.open.UserStream.withStream(UserStream.scala:58)
        at io.gatling.core.controller.inject.open.OpenWorkload.injectBatch(OpenWorkload.scala:35)
        at io.gatling.core.controller.inject.Injector.$anonfun$inject$1(Injector.scala:60)
        at io.gatling.core.controller.inject.Injector.$anonfun$inject$1$adapted(Injector.scala:59)
        at scala.collection.Iterator.foreach(Iterator.scala:941)
        at scala.collection.Iterator.foreach$(Iterator.scala:941)
        at scala.collection.AbstractIterator.foreach(Iterator.scala:1429)
        at scala.collection.MapLike$DefaultValuesIterable.foreach(MapLike.scala:213)
        at io.gatling.core.controller.inject.Injector.io$gatling$core$controller$inject$Injector$$inject(Injector.scala:59)
        at io.gatling.core.controller.inject.Injector$$anonfun$1.applyOrElse(Injector.scala:92)
        at io.gatling.core.controller.inject.Injector$$anonfun$1.applyOrElse(Injector.scala:82)
        at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:38)
        at akka.actor.FSM.processEvent(FSM.scala:684)
        at akka.actor.FSM.processEvent$(FSM.scala:681)
        at io.gatling.core.controller.inject.InjectorFSM.processEvent(InjectorFSM.scala:37)
        at akka.actor.FSM.akka$actor$FSM$$processMsg(FSM.scala:678)
        at akka.actor.FSM$$anonfun$receive$1.applyOrElse(FSM.scala:672)
        at akka.actor.Actor.aroundReceive(Actor.scala:517)
        at akka.actor.Actor.aroundReceive$(Actor.scala:515)
        at io.gatling.core.akka.BaseActor.aroundReceive(BaseActor.scala:24)
        at akka.actor.ActorCell.receiveMessage(ActorCell.scala:588)
        at akka.actor.ActorCell.invoke(ActorCell.scala:557)
        at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:258)
        at akka.dispatch.Mailbox.run(Mailbox.scala:225)
        at akka.dispatch.Mailbox.exec(Mailbox.scala:235)
        at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
        at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
        at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
        at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
16:40:28.359 [GatlingSystem-akka.actor.default-dispatcher-2] DEBUG io.gatling.core.action.Exit - End user #1
16:40:28.360 [GatlingSystem-akka.actor.default-dispatcher-2] DEBUG io.gatling.core.controller.inject.open.OpenWorkload - Start user #1
16:40:28.363 [GatlingSystem-akka.actor.default-dispatcher-2] DEBUG io.gatling.core.controller.inject.open.OpenWorkload - Injecting 4 users in scenario my-api, continue=true
16:40:28.364 [GatlingSystem-akka.actor.default-dispatcher-2] DEBUG io.gatling.core.controller.inject.Injector - End user #1
16:40:29.347 [GatlingSystem-akka.actor.default-dispatcher-2] DEBUG io.gatling.core.controller.inject.open.OpenWorkload - Injecting 0 users in scenario my-api, continue=true
16:40:29.373 [GatlingSystem-akka.actor.default-dispatcher-2] ERROR com.intuit.karate.gatling.KarateAction - 'classpath:org/mycompany/karate/tests/myAPI.feature@test=myTag' crashed on session Session(my-api,2,1558395629372,Map(),0,OK,List(),io.gatling.core.protocol.ProtocolComponentsRegistry$$Lambda$329/1759250827@7cee98de), forwarding to the next one
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have a gradle project with scala and java, and had to create a gradle task to move resources to the right folder, in order to make them available.

task copyResources(type: Copy) {
  from ("src/test/java/") {
    include "/**/*.feature"
    include "karate-config*.js"
    include "logback*.xml"
    include "/**/*.csv"
    include "/**/*.json"
  }
  into "$buildDir/classes/java/test/"

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...