How to run single Jasmine test in IntelliJ IDEA - intellij-idea

Is it possible to run single Jasmine test it or suite describe in IntelliJ from popup menu as it possible with JUnit or TestNG fremeworks?
Now I can only execute tests by running karma.conf.js that will grab all specs and run them which is not exactly what I want.
Updates
This is known issue please upvote it.

You don't need Intellij's help if you are trying to run a single unit test or a single test suite while using Jasmine. You can do that with their feature of fit() and fdescribe(). Here, prepending it(...) and describe(...) with f says those are focused tests/test suites.
Quoting the documentation (Jasmine 2.1 and above),
Focusing specs will make it so that they are the only specs that run.
Any spec declared with fit is focused.
You can focus on a describe with fdescribe

You could follow this issue in YouTrack - https://youtrack.jetbrains.com/issue/WEB-13173.
We have supported --grep[1] option for jasmine in karma already.
But there are some open discussions about problems in large projects[2]
[1] - https://github.com/karma-runner/karma-jasmine/pull/56
[2] - https://github.com/karma-runner/karma/issues/1235
Thanks!

With WebStorm 2017.1 it's possible to use RunConfiguration producer to run a single Karma test: https://github.com/develar/ij-rc-producer

Related

What is the gradle command to run scenarios with tags?

I am using Gradle 7.6, Karate 1.3.1, Java 17.0.5 and Junit 5.8.1.
I want to configure a Jenkin job for each feature to create a health check monitor. I need gradle commands to run feature files using tags #smoke, #regression, #featureName etc.,
I have tried with the following command, it worked earlier and stopped working recently.
./gradlew test -Dkarate.options="--tags #smoke" -Dtest.single=TestRunner#testTagsWithoutFeatureName
Where TestRunner is the following Java class
import com.intuit.karate.junit5.Karate;
public class TestRunner {
#Karate.Test
Karate testTagsWithoutFeatureName() {
return Karate.run().tags("#smoke").relativeTo(getClass());
}
}
My advice is use the Runner class, that is better designed for running tests in CI. The JUnit helpers are just for local-dev convenience: https://stackoverflow.com/a/65578167/143475
It should be possible to even pass a feature to karate.options as the last argument. Which might be more convenient than writing a Java class for every combinations. You should experiment.
Otherwise no suggestions, but if you feel there's a bug, follow this process: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue

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.

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

AngularJS : e2e tests with Karma Scenario Test Runner using cached source?

I am trying to set up some AngularJS e2e tests with Karma Scenario Test Runner. I did some modifications to the source files, but Karma doesn't seem to use these latest versions when testing.
In the source files, I added ids to some elements. Karma still couldn't find them, so I added a pause in the e2e test, so that I can mark and "Inspect elements" (using Chrome) on the current page in the test runner. The source code seems correct, except the latest changes are missing, i e, the ids aren't there. So what's happening here? Do I need to explicitly tell Karma the files have been updated somehow?
You can fix this issue by forcing angularjs to clear the application cache:
app.run(function($rootScope, $templateCache) {
$rootScope.$on('$viewContentLoaded', function() {
$templateCache.removeAll();
});
});
In Chrome developer tools settings, check "Disable cache (while DevTools is open)".
Obviously, this is a much more general issue than Angular's e2e test runner, but I decided to leave it here for now, in case somebody else has the same question.

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