Cucumber with Gradle for Java - java

I use Gradle for building my project and I have some trouble between cucumber and gradle. For example:
I have a feature file, which I run with JUnit RunWith annotation. But if I want to run 1 scenario by tag, I write this:
-Dcucumber.options= --tags #1 #2 and try to run it.
But Gradle doesn't see this command and runs all tests. So, how can I correctly apply cucumber plugin into Gradle?

So, I found one way to do it. All we need is to use testCompile with JUnit, not cucumber-junit and all is right.

Related

Does infinitest for IntelliJ IDEA honor the run tests settings in Gradle?

I have a Gradle project that I would like to use infinitest with. However, while all test pass using the Gradle test runner, many fail in infinitest. Is this because infinitest uses the IntelliJ test runner to run the tests?
I expect this is the case since I get similar results when I try to run tests manually using the IntelliJ test runner.
How can I configure infinitest to use Gradle as the test runner?
Infinitest starts a new JVM to run tests, it gets the project classpath from IntelliJ but does not know it is a Gradle project.
I don't know what the Gradle test runner does differently but it would be great if you could open an issue on the Infinitest bug tracker with the steps to reproduce the problem (ideally with a sample project).
In case the issue is with missing JVM options you can set them using the infinitest.args file

connect Karate with selenium

I would like to use karate and selenium together. I have read how to call "JavaApiTest class" . To get "JavaApiTest"class working, I added karate -core dependency. If I try to run my tests from cucumber runner then I get the
following error:
java.lang.NoSuchMethodError:
com.intuit.karate.cucumber.CucumberRunner.(Ljava/lang/Class;)V,
So probably the Cucumber runner has conflict with this dependency, if I remove this dependency than CucumberRunner.runFeature and CucumberRunner.runClasspathFeature miss the corresponding jar files.
I have also another question:
How can I run cucumber and karate features at the same time so that the results are summarized in one report.
You can't mix Cucumber and Karate like this, refer this issue: https://github.com/intuit/karate/issues/398
If you are having library conflicts, and you think this is a Karate issue, please follow these instructions: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Gradle Plugin to generate cucumber report not compiling

I am writing Cucumber Automated Test Cases in java, using REST Assured.
All the tests run as JUnit tests, & as Gradle tests, & they all pass successfully.
The next step I need to take is to generate a Cucumber Report based on these test results.
I've been told that I need to find a gradle plugin for cucumber.
So far, I've tried putting the following code (from here: https://plugins.gradle.org/plugin/com.github.spacialcircumstances.gradle-cucumber-reporting) into my build.gradle file:
plugins {
id "com.github.spacialcircumstances.gradle-cucumber-reporting" version "0.0.12"
}
But, when I try to refresh the gradle, I get this error:
Sychrnoize Gradle projects with workspace failed due to an error in the referenced Gradle build.
Is this the correct plugin to generate this cucumber report, and if so, why is it not being accepted by the gradle?

Running JUnit tests together with Java project

I'm writing code in Intellij and have a JUnit test class included in a project and i understand that running of JUnit should always be done at build time.
Is there a way to first run the JUnit and only if there were no test error run the project itself ? I want them to run together with 1 click (NOT run them seperately/manually).
Also, i would like the above to work even when the project is packed as a .jar file.
How can it be done ?
Thanks !
In Intellij:
Run -> Edit Configurations
Create a JUnit configuration for your tests
Create a Run configuration for your project.
And on "Before Launch": Add -> Run Another Configuration and choose the one created at point 1.
It doesn't matter how your project is packed (jar, ...)
Normally this is done by using a build management tool like: maven, gradle, ant. In this way the build tool will run tests for you and stop if they fail.
With maven, it's just a command: mvn clean package exec:java which will compile code, build project, run tests and execute your code.
See example project: https://github.com/HaveACupOfJava/maven-jar-demo

How do I run JUnit tests in Gradle

I have JUnit tests that have a rest-assured dependency.
How can I run these in Gradle?
I have no idea what you mean by 'rest assured' tests but I'll assume you just want to run either JUnit or TestNG tests in gradle. You should really remove any maven references from your question to avoid confusion... this is a simple Gradle question and has nothing to do with Maven.
The following line in your build.gradle
apply plugin: java
Adds the java plugin to your build which adds appropriate test tasks to your build. Please see the java plugin documentation for configuring JUnit / TestNG

Categories

Resources