Cucumber step definiton not found - InteliJ Gradle - intellij-idea

I have following problem. I have feature file as follows:
Feature: Serve coffee
Coffee should not be served until paid for
Coffee should not be served until the button has been pressed
If there is no coffee left then money should be refunded
Scenario: Buy last coffee
Given there are 1 coffees left in the machine
And I have deposited 1$
When I press the coffee button
Then I should be served a coffee
InteliJ highlights Given, And etc as missing step definitons. I generate definitions and InteliJ still doesn't recognize them. I'm using Cucumber gradle plugin with following configuration:
cucumber {
formats = ['pretty','json:build/cucumber.json','junit:build/cucumber.xml']
glueDirs = ['src/test/resources/step_definitions']
featureDirs = ['src/test/resources/features']
}
I'm really not sure what I'm doing wrong there. Thanks in advance for any advice!

Try to check whether you have a correctly installed Cucumber for Java plugin in Intellij Idea. (Settings/Plugins).
Try to review your features and glue parameters. Cucumber by default will look for features to src/test/resources folder and for step definitions - to src/test/java. (actually in glueDirs option you have set path to steps in resources folder).
So try to modify your runner options like:
cucumber {
formats = ['pretty','json:build/cucumber.json','junit:build/cucumber.xml']
glueDirs = ['step_definitions']
featureDirs = ['features']
}
Also in case of any problems you can try to use classpath in options:
cucumber {
formats = ['pretty','json:build/cucumber.json','junit:build/cucumber.xml']
glueDirs = ['classpath:step_definitions']
featureDirs = ['classpath:features']
}

There is a Cucumber plugin for IntelliJ. Make sure that you have it installed.
The steps in your feature file will be marked as missing step definition until this plugin is installed.

Related

alternate way to set Build and run using IntelliJ IDEA

I am working with Java source code with TestNG and frequently see errors like no test found to run OR Test event were not received whenever I try to run test cases in IntelliJ IDEA.
Which I can fix with changing Build and run using IntelliJ IDEA from Gradle.
I am looking for alternative way using which can add this somewhere as configuration instead of going and changing this manually.
You can use gradle-idea-ext-plugin to set build and run actions right in the Gradle build script:
import static org.jetbrains.gradle.ext.ActionDelegationConfig.TestRunner.CHOOSE_PER_TEST
plugins {
...
id "org.jetbrains.gradle.plugin.idea-ext" version "1.0"
...
}
idea.project.settings {
delegateActions {
delegateBuildRunToGradle = true // Delegate Run/Build to Gradle
testRunner = CHOOSE_PER_TEST // Test execution: PLATFORM, GRADLE or CHOOSE_PER_TEST
}
}
But actually, the fact that it works with IDE runner, but does not work with Gradle runner may indicate problems. I would first check if it works from the command line Gradle - make sure you run the same test with it as from the IDE. If it works in terminal but does not work in IDE, I would report a bug at YouTrack with reproducible sample.

Karate summary reports not showing all tested features after upgrade to 1.0.0

I have recently upgraded to version 1.0.0 from 0.9.6 and noticed that the generated karate-summary.html file, it doesn't display all the tested feature files in the JUnit 5 Runner unlike in 0.9.6.
What it displays instead was the last tested feature file only.
The below screenshots are from the provided SampleTest.java sample code (excluding other Tests for simplicity).
package karate;
import com.intuit.karate.junit5.Karate;
class SampleTest {
#Karate.Test
Karate testSample() {
return Karate.run("sample").relativeTo(getClass());
}
#Karate.Test
Karate testTags() {
return Karate.run("tags").relativeTo(getClass());
}
}
This is from Version 0.9.6.
And this one is from Version 1.0.0
However, when running the test below in 1.0.0, all the features are displayed in the summary correctly.
#Karate.Test
Karate testAll() {
return Karate.run().relativeTo(getClass());
}
Would anyone be kind to confirm if they are getting the similar result? It would be very much appreciated.
What it displays instead was the last tested feature file only.
This is because for each time you run a JUnit method, the reports directory is backed up by default. Look for other directories called target/karate-reports-<timestamp> and you may find your reports there. So maybe what is happening is that you have multiple JUnit tests that are all running, so you see this behavior. You may be able to over-ride this behavior by calling the method: .backupReportDir(false) on the builder. But I think it may not still work - because the JUnit runner has changed a little bit. It is designed to run one method at a time, when you are in local / dev-mode.
So the JUnit runner is just a convenience. You should use the Runner class / builder for CI execution, and when you want to run multiple tests and see them in one report: https://stackoverflow.com/a/65578167/143475
Here is an example: ExamplesTest.java
But in case there is a bug in the JUnit runner (which is quite possible) please follow the process and help the project developers replicate and then fix the issue to release as soon as possible.

Intellij IDEA > Cucumber Test Results don't display Scenario name

Problem:
When running my Cucumber Acceptance tests from Intellij, the Test Results don't display the scenario name, just <no name> - making it difficult/impossible to determine which Scenario actually failed!
e.g.
I'm using JDK8 with Intellij IDEA 15 Community Edition (Build #IC-143.2287) with the following Intellij IDEA plugins:
Cucumber for Java (v 143.382) - github.com / plugins.jetbrains.com
Cucumber for Groovy (v 143.382) - github.com / plugins.jetbrains.com
The following Cucumber libraries (gradle):
testCompile "info.cukes:cucumber-junit:1.2.4"
testCompile "info.cukes:cucumber-java8:1.2.4"
testCompile "info.cukes:cucumber-spring:1.2.4"
This is my AcceptanceTests.groovy file:
import cucumber.api.CucumberOptions
import cucumber.api.junit.Cucumber
import org.junit.runner.RunWith
#RunWith(Cucumber.class)
#CucumberOptions(
strict = false,
plugin = ["pretty", "html:build/reports/cucumber"],
tags = ['~#ignore']
)
public class AcceptanceTests {}
Just wondering:
Is there anyway to display the scenario name?
Is it something I'm doing OR is it just not implemented yet? (OR does it exist in the Intellij IDEA Ultimate Edition?)
Who can I suggest this feature to, if it doesn't exist yet?
Update - 21/03/2016
I've forwarded my question to the author (Andrey Vokin) and raised an issue - https://youtrack.jetbrains.com/issue/IDEA-153338 .
I have same problem, and found where it's coming from in my case. For "scenario" at least, it seems to come from dots (".") : remove them from your scenario description and see what happens.
I was also facing the same problem, but I haven't used any dots (".") in scenario description. Though the full stop (dot) was present in the Feature file description and after removing that it worked for me.
Feature file description:
After result how it looks like:

Undefined step definitions in IntelliJ

I'm trying to follow this article to match Cucumber specs with step definitions in IntelliJ.
When I press Alt+Enter, I see Inspection 'Undefined Step' options. However, I should see the intention action Create Step Definition.
I thought I had the Cucumber IntelliJ plugin installed, so that shouldn't be a problem. Any help is greatly appreciated.
Turns out I had the Gherkin plugin but not the Cucumber for Java plugin.
I wasted around an hour to solve this. My issue was, Idea was able to navigate from feature to step file. But when I wanted to execute one cucumber test from feature file (Right click and Run Scenario), it was giving error as undefined steps.
Solution: In the Edit Configuration -> provide the Glue for the cucumber which should be absolute path till steps folder. Please see below screen shot
This fixed my problem of running feature file from Idea.
Hope this helps others.
Most probably you need to install the cucumber for java plugin, if already installed then you need to enable from File>>Settings>>pugins.
I had to uncheck the "Create separate module per source set" checkbox under the "Build, Execution, Deployment" -> "Build Tools" -> "Gradle" settings, and then rebuild the project.
"Undefined" step error message would appear if you import a new BDD project.
This error could appear due to two reasons.
If you have not installed the "Cucumber for Java" plugin.
If you import any BDD projects then it will not detect step definition file.
Solution:
1. If the plugin is not found then you need to install from the below location.
File->Settings->Plugins->MarketPlace->Cucumber for Java
2. After Importing the project disable the plugin and enable once again in the Installed section under Installed.
For me there was a collision between Sidesteps plugin and Cucumber plugin in Intellij and as a result *.feature file extension was taken over by the Sidesteps plugin and was expecting Sidesteps step definitions ignoring Cucumber step definitions. No clue what Sidesteps actually is. So went to IntelliJ settings and reassigned the *.feature extension to Cucumber Scenario type and then everything worked fine and Cucumber steps are recognized by Intellij now.
I had the same issue where all of a sudden my feature to step definition glue was missing. All i did was goto Run->Edit Configurations->and removed the cucumber java
configuration and restarted IntelliJ. it worked fine.
I found that even with the Cucumber for Java plugin installed it was still generating only one step. I eventually uninstalled the Cucumber for Java plugin and reinstalled it and all step definitions were generated.
The issue was fixed after updating the Intelij to the latest version and after updating the cucumber and gherkin intelij plugins
Me not help not one of suggestions above.
But i find if you start one test from runner the problem goes on (it is worked if you have runner for some tests( Runner is class that have line #CucumberOptions(
features = "src/test/resources/stability_*****_features/",
glue = "steps"
)
And may be the next line in config helped you^
in configurations i put line: --plugin org.jetbrains.plugins.cucumber.java.run.CucumberJvm4SMFormatter
in Programm arguments line - it help me
If still not working, you can add runner class
add -> runner package -> Main Runner class
-test
-runner - Create this package
-stepPackage
-resources
-features
#CucumberOptions(features = {"classpath:features"}, glue = {"stepDefinition"},
monochrome = false,dryRun = false)
public class MainRunner extends AbstractTestNGCucumberTests {
}
That is it. Just run this class first. Right mouse click and Run'MainRunner'
Then it will work if you just go back and run Scenarios as well
I had the same issue and was resolved by going to Run> Edit configuration> Before Launch then click on the add option "+" and add Build Project option.
enter image description here

How to configure IntelliJ for running test with JUnit 4?

Should be simple but I couldn't figure it out.
When running my unit test inside IntelliJ, I could not find a way to tell IntelliJ-9.0 that it should use JUnit4 instead of JUnit3.
When a test fails, IntelliJ console displays:
MyTests.testConstraints(MyTests.groovy:20) at
...
com.intellij.junit3.JUnit3IdeaTestRunner.doRun(JUnit3IdeaTestRunner.java:108)
at
com.intellij.junit3.JUnit3IdeaTestRunner.startRunnerWithArgs(JUnit3IdeaTestRunner.java:42)
...
Do you know how to replace JUnit3 by JUnit4 ?
I found it!
Go to Run/Debug Configurations
Add new configuration and choose a JUnit
In the configuration tab, add "-junit4" to the Test run parameters input field
And that's done !
You can annotate your test class with an annotation to indicate junit the runner it will use
#RunWith(JUnit4.class) MyTestClass {}
I tried to put:
#RunWith(JUnit4.class)
at the beginning of a test.
IntelliJ complained about this, but asked to 'load' JUnit4.class.
So I deleted #RunWith(JUnit4.class).
But the 'loading' seems to have fixed the problem - #Ignore is now respected!
Put the JUnit 4 JAR in your CLASSPATH and see if IntelliJ picks it up.
The JUnit plug-in appears to run either version 3 or 4.
I'll bet that it has to do with the way you're writing your JUnit tests. Post one to confirm. If you use the JUnit 4 style, I'll bet IntelliJ would run it properly.
'com.intellij.junit3' package belongs to IDEA binaries, not to junit3 or junit4. So, the question itself seems to be incorrect in essence - there is no difference in what package name is used by IDEA codebase internally if it correctly executes the tests.
It sounds like the real problem may be that you are trying to use junit 4 with a grails version less than 1.3. Grails 1.2.x and lower only support Junit 3 tests. Grails 1.3 will finally have junit 4 support. This was discussed on stackoverflow link text
I had the same problem with a java app inside 10.5, and it turned out to be my Project language level set to 5.0 as opposed to 8.0.
To change this go to File->Project Structure->Project->Project language level
And change this to the required level. Not sure at which level you can use JUnit4, but setting this to 5.0 will make it use JUnit3. Setting it to 8.0 makes it use JUnit4