Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Karate Gatling with gradle build is not working [duplicate]

Tags:

gradle

karate

I am trying to run gatling with karate in gradle build and getting below error,

/smoketests/SmokeTestRunner.java:19: error: package org.junit.runner does not exist
import org.junit.runner.RunWith;
                       ^
/smoketests/SmokeTestRunner.java:21: error: package com.intuit.karate.junit4 does not exist
import com.intuit.karate.junit4.Karate;
                               ^
/smoketests/SmokeTestRunner.java:30: error: cannot find symbol
@RunWith(Karate.class)
 ^
  symbol: class RunWith
/wskadmin/WskAdminRunner.java:19: error: package org.junit does not exist
import org.junit.Test;
                ^
/wskadmin/WskAdminRunner.java:20: error: package org.junit.runner does not exist
import org.junit.runner.RunWith;
                       ^
/wskadmin/WskAdminRunner.java:22: error: package com.intuit.karate.junit4 does not exist
import com.intuit.karate.junit4.Karate;

and exception as

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':compileGatlingScala'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
        at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
        at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:60)

For more information, below is my build.gradle file,

plugins {
  id "com.github.lkishalmi.gatling" version "0.7.3"
}

apply plugin: 'java'
apply plugin: 'maven'

group = 'karate-gatling'
version = '1.0-SNAPSHOT'    
sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}    
repositories {
     mavenCentral()
     maven { url "http://repo.maven.apache.org/maven2" }
}

sourceSets {
    gatling {
        scala.srcDirs = ['src/test/java']
    }
    test {
        java 
            {  
                srcDir file('src/test/java')
                // exclude '**/*.java'
            }
        resources
            { 
                srcDir file('src/test/java')
                // exclude '**/*.java'
            }
    }
}  
dependencies {
    compile group: 'com.jcraft', name: 'jsch', version:'0.1.53'
    compile group: 'org.apache.logging.log4j', name: 'log4j-api', version:'2.10.0'
    compile group: 'org.apache.logging.log4j', name: 'log4j-core', version:'2.10.0'
    compile group: 'com.intuit.karate', name: 'karate-netty', version:'0.8.0.1'
    testCompile group: 'net.masterthought', name: 'cucumber-reporting', version:'3.8.0'
    testCompile group: 'com.intuit.karate', name: 'karate-apache', version:'0.8.0.1'
    testCompile group: 'com.intuit.karate', name: 'karate-junit4', version:'0.8.0.1'
    testCompile group: 'com.intuit.karate', name: 'karate-gatling', version:'0.8.0.1'
    gatling 'com.intuit.karate:karate-gatling:0.8.0.1'
    gatling 'com.google.code.gson:gson:2.8.0'              
    gatling 'org.apache.httpcomponents:httpclient:4.3.2'
    gatlingCompile 'org.apache.commons:commons-lang3:3.4'
    gatlingRuntime 'cglib:cglib-nodep:3.2.0'
}
gatling {
    sourceRoot = 'src/test/java'
    toolVersion = '2.3.1'
}

to run my simulation class i am using below command,

./gradlew clean gatlingRun-mypackage.LoadTest

Below is my LoadTest.scala file

class LoadTest extends Simulation {
  before{
    println("Simulation is about to start!")
  }
  val createActionTest = scenario("smoke").exec(karateFeature("classpath:path/myfeature.feature"))


  setUp(createActionTest.inject(rampUsers(5) over (5 seconds))
    ).maxDuration(1 minutes).assertions(global.responseTime.mean.lt(1100))

  after {
    println("Simulation is finished!")
  }
}

And below is my runner file

import org.junit.runner.RunWith;
import com.intuit.karate.junit4.Karate;
import cucumber.api.CucumberOptions;

@RunWith(Karate.class)
@CucumberOptions(tags = {"~@ignore","~@driver","~@reliability","~@resiliency","~@concurrent","~@wskfunctions"})
public class SmokeTestRunner {

}

Any help on this is really appriciated

like image 218
Manoj Mishra Avatar asked Aug 21 '18 18:08

Manoj Mishra


1 Answers

You need to add a testCompile dependency on JUnit, such as:

testCompile 'junit:junit:4.12'

gradle karate karate-gatling junit gradle-gatling-plugin

like image 163
Bruce Faulkner Avatar answered Oct 03 '22 18:10

Bruce Faulkner