Karate Gatling - How to run Gatling tests using Maven uber jar [duplicate] - karate

I am using karate 0.9.2 with gradle. My project requires to have all karate tests inside src/main/java. So I configured the gradle dependency as ‘compile’ instead of ‘testCompile’ and also modified the sourceSets to point to main instead of test. When I ran my runner class with above configuration I got empty test suite message.
build.gradle snippet:
compile 'com.intuit.karate:karate-junit4:0.9.3'
compile 'com.intuit.karate:karate-apache:0.9.3'
sourceSets {
test {
resources {
srcDir file('src/main/java')
exclude '**/*.java'
}
}
}
Additionally, I have is to run the karate tests from the deployable project jar. Please point me the resources I can refer to achieve the same.

Not something we directly support but teams have done this in Spring Boot etc. It should be possible, see if this thread helps: https://github.com/intuit/karate/issues/520
Also you may not need JUnit also: https://github.com/intuit/karate/issues/427
And see the sample project in this ticket as an example: https://github.com/intuit/karate/issues/529
EDIT - in 1.0 onwards we hope that class-loading from spring-boot JAR files is more reliable: https://github.com/intuit/karate/issues/751

Related

Converting current project into Cucumber

We already have a working project in test NG and now we are trying to add cucumber framework to it.
Sofar, I could goto eclipse marketplace and download the cucumber plugin, also added cucumber dependencies into my gradle file.
Then I have created a feature file - login.feature and its corresponding step definition for it. In the same feature file I have right clicked -> run as -> (selected) cucumber feature, now the issue is eclipse is unable to recognize the step definition for its corresponding feature file and the executed console in the attached screenshots.
Output:
0 Scenarios
0 Steps
0m0.567s
Please see the attached screenshots for more information.
If you just need to see whether feature file is running, first you need to make sure that Cucumber Eclipse Plugin is properly installed, Eclipse needs to be restarted after installation. If you are using TestNG then Cucumber-TestNG and Cucumber-Java dependencies of same version should be used. I could see Cucumber-TestNG dependency missing. You need to exclude JUnit also.
Then in order to run feature file, you first need to configure it, by selecting Run Configuration->click Cucumber feature(left panel)->select project->provide Feature file location->Apply and Run
You can also create a Test Runner which will link Feature file with Step definition and run the test as TestNG test from Runner.
Eg. Test Runner
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
#CucumberOptions(features = "src/test/resources/featureFiles", glue = "stepDefinitions")
public class RunTestNGTest extends AbstractTestNGCucumberTests {
}

How do I create a Gradle project that depends on the JS from a Kotlin project?

I am using Kotlin to share logic between my back end (Java Spring Web) and front end. Getting the Java back end to call the Kotlin logic is easy: I made both part of the same Gradle Multiproject build and have the server project depend on the Kotlin project.
Now I need to get the generated JavaScript out of Kotlin and into a format where the server can serve it. Looking through the Gradle output jar for the server, it only has the jvm jar and not the js jar.
I had a similar problem in this GitHub project with a Spring Boot backend and a Kotlin/JS frontend + common code.
If everything is in the same repo in multiple Gradle subprojects, you can use the following in the server subproject to bundle the produced JS as resources into your server's jar:
tasks.processResources {
// make sure we build the frontend before creating the jar
dependsOn(":frontend:assemble")
// package the frontend app within the jar as static
val frontendBuildDir = project(":frontend").buildDir
val frontendDist = frontendBuildDir.toPath().resolve("distributions")
from(frontendDist) {
include("**/*")
into("static")
}
}
It's not ideal (I don't like inter-project dependencies like this), but it does the job.
Spring Boot then automatically serves the static files from this place in the jar (/static).

How to use newer version of a library with Spring Boot

I am developing an application using Spring Boot 1.5.9.RELEASE, and I am using Gradle as build tool.
I want to use SelenumHQ 3.8.1 in the project.
When I was building the project I noticed that Selenium 2.53.1 was added to project (not 3.8.1), so I investigated and found out the reason.
There exists following statement in my build.gradle:
dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:1.5.9.RELEASE")
}
}
and in that file selenium.version property is set to '2.53.1'.
So I have changed the statement to
dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:1.5.9.RELEASE") {
bomProperty 'selenium.version', '3.8.1'
}
}
}
but now IDEA shows both 3.8.1 and 2.53.1 as dependencies of the project, and when I build the artifact using gradle, there only exists 2.53.1 dependencies and no sign of 3.8.1.
How can I change this behavior and use Selenium 3.8.1?
P.S. The Selenium is made of multiple jar files, so it is not just a single Jar file, and I want to update all of them in the most minimized using gradle.
I have found the answer in here.
I shall override the property using: ext['selenium.version']='3.8.1' statement.
When IntelliJ imports the dependencies, it will not remove old dependencies like this.
You would have to clean it out, then re-import the dependencies. Of course, another dependency might also have a dependency on 2.53.1 that would bring it in again.
I don't know Gradle, but maven you can do a mvn tree dependency that would list all the dependencies and further down and you can look through it to see if selenium is a dependency for another dependency too.

Merging Android unit test and connected test code coverage data is broken

Version 2.3.3 of the Android Gradle Plugin was able to provide merged unit test and connected test code coverage data. In version 3.0.0, this capability is broken because each of the test types use a different and incompatible version of JaCoCo. Rafael Toledo provided a Medium blog post showing how to make this work with 2.3.3. I have provided a Github repo that illustrates the working code and the broken code in a few branches. The repo documentation provides a Readers Digest description of the problem. At this point I am convinced the Gradle Plugin team owns the issue and will file a bug shortly. My questions are:
1) Can anyone suggest a viable workaround? (there is a suggested fix by Carmen Alvarez posted to the Medium blog post but I get no joy from it.)
2) Can someone point me to instructions on how to hack and build the Gradle Android Plugin to test out a potential fix? (I found the answer to this one at http://tools.android.com/build/gradleplugin )
According to Android Plugin DSL Reference that contributes Android specific things:
To specify the version of JaCoCo you want to use, you now need to include it as a buildscript dependency in your project-level build.gradle file, as follows:
buildscript {
dependencies {
classpath "org.jacoco:org.jacoco.core:<jacoco-version>"
...
}
}
Previously Android Plugin had
android {
jacoco {
version = "<jacoco-version>"
}
}
According to Gradle JaCoCo Plugin documentation that contributes task of type JacocoReport:
The JaCoCo plugin adds a project extension named jacoco of type JacocoPluginExtension, which allows configuring defaults for JaCoCo usage in your build.
jacoco {
toolVersion = "<jacoco-version>"
}
And so here is modification for your https://github.com/pajato/acc that allows to align versions so that execution of ./gradlew clean jacocoTestReport succeeds:
buildscript {
dependencies {
classpath "org.jacoco:org.jacoco.core:0.7.9"
}
}
allprojects {
apply plugin: "jacoco"
jacoco {
toolVersion = "0.7.9"
}
}

Why does gradle idea plugin configure classpath to use unprocessed/source test resources instead of filtered/generated resources

I'm trying to run my test cases in idea 12 after configuring my multi-project build with the gradle idea plugin. My project is configured to use the gradle defaults for test resources (src/test/resources). I apply some filtering to these resources:
// filter test resources
processTestResources {
doLast {
ant.replace(dir: sourceSets.test.output.resourcesDir, replacefilterfile: testProps, includes: "**/*.xml,**/*.properties")
}
}
Additionally processTestResources depends on a custom task that copies some "generated" files to sourceSets.test.output.resourcesDir.
Many of my tests are failing, because they rely on the filtered test resources. When I look at the classpath that is being used for the test cases, it is pointing to rootProject/out/test/targetProject. When I look in there I see my test classes and my pre-filtered resources (and non of the resources that I explicitly copied over before processing the test resources). It appears they have simply been copied from src/test/resources. Is this expected behavior?
Also, why are the test classes and resources put into rootProject/out/rootProject as opposed the the defaults gradle defaults rootProject/targetProject/build/...?
When you build in IDEA, Gradle isn't involved. It's IDEA that's copying the resources and compiling the code. You can add Gradle-generated resources to the IDEA build, but you have to run the corresponding Gradle tasks yourself, or configure IDEA run configurations to invoke the tasks. (I can't seem to find a post-compilation hook in IDEA.)