I'm new to this so excuse me if this is an obvious question...
I'm running a JUnit test in Eclipse using a cucumber framework. I have arrived at a point where everything is now working, however, the JUnit output does not prefix the entries with the Gherkin descriptions, i.e. Scenario:, Given:, Then:, When:, etc. Every example I've found online, they just seem to be there as standard.
I've tried adding a multitude of different jar files (just in case I was missing something specific) with no success, and I've also run through all the obvious preferences/config settings but it's just not happening.
The version of eclipse I'm using is - Version: Neon.3 Release (4.6.3), Build id: 20170314-1500
with JUnit4
Not sure if anyone can assist? but if you need any other information please let me know as I've hit a bit of a brick wall....
Many thanks
Carl
Related
I've recently migrated to IntelliJ and need to solve a particular problem: I have a project that has numerous modules; one of these modules is purely for testing and contains a number of errors:
.
I'd like to suppress all warnings/errors/inspections on NNGINETest in this screenshot. Is there a way to configure the project to do that? I found this answer: How do I disable some inspections for modules in IntelliJ IDEA? but I'm not quite sure it's for the same thing. On top of that, the answer was a bit unclear to me and I wasn't able to understand all of the steps because of how new and unfamiliar with IntelliJ that I am.
If someone could please thoroughly explain to me how to solve this problem, I would be grateful.
Since you have errors in NNGINETest, I suppose you don't need to run it. So I would suggest marking the src folder under NNGINETest as excluded. like:
I tried to expand Eric's answer but it was rejected for arbitrary reasons, so I'm writing my own to try and clarify some more for anyone else that runs into this problem since I hate bureaucracy. Adding it as an answer will allow me to provide some visual aids:
NNGINETest has errors that are reported in building. Eric's answer is correct in that we can exclude it, but the problem is that the console is still spammed with error reports upon building when I right clicked the project and marked it for exluding that way. I fixed it by excluding it via the menu in File -> Settings -> Build, Execution, Deployment -> Compiler -> Excludes
You'll want to probably also make sure that the "Recusively" checkboxes are checked for modules you want to exclude.
I don't really know what the difference is here between this and using the right click menu option (I couldn't find anything in the IntelliJ manual about it either but maybe someone can provide a link in the comments), but this successfully prevented NNGINETest from littering the console during building:
Additionally, using the Excludes menu rather than the directory marking for the module allows it to still appear in the Project module list rather than disappearing. An "x" will appear by excluded folders. This is pretty useful in my opinion:
Hope this helps!
Folder structure
I am trying to create step definition from the feature file, but the steps in feature file does not get highlighted even if i press alt+enter. (Please refer to the image and ignore the ":")
But the same was working a couple of days back, so not sure whether I messed up something.
Please let me know my mistake
OK so i figured out the problem. I had installed a cucumber.js few month back which was causing the problem. I uninstalled cucmber.js though my IDE and then just used cucumber java and it worked fine.
To get rid of this issue in the future, you can try some other cucumber editor like Cucumber Eclipse Plugin 1.0.0.202005150629 or Natural 0.9
I'm using JUnit since I started this project and everything works just fine. I have a couple of hundreds tests, and of course, here and there I start them all. Right click on root test folder, run (or debug) with JUnit.
But since yesterday, when I do that, the result is:
Process finished with exit code 0
without starting any of tests. Same thing is with any folder in folder tree. I can still run a single test class, but I really need an option to start them all.
If any of you have any ideas, please drop them here.
Here is what is logged when I try to run tests:
2012-10-31 15:16:55,693 [2727217] ERROR - ij.psi.impl.source.PsiFileImpl - IntelliJ IDEA 11.1.2 Build #IU-117.418
2012-10-31 15:16:55,693 [2727217] ERROR - ij.psi.impl.source.PsiFileImpl - JDK: 1.6.0_31
2012-10-31 15:16:55,693 [2727217] ERROR - ij.psi.impl.source.PsiFileImpl - VM: Java HotSpot(TM) Client VM
2012-10-31 15:16:55,693 [2727217] ERROR - ij.psi.impl.source.PsiFileImpl - Vendor: Sun Microsystems Inc.
2012-10-31 15:16:55,693 [2727217] ERROR - ij.psi.impl.source.PsiFileImpl - OS: Windows 7
2012-10-31 15:16:55,693 [2727217] ERROR - ij.psi.impl.source.PsiFileImpl - Last Action: RunClass
2012-10-31 15:16:55,693 [2727217] ERROR - m.intellij.util.ExecutorsQuery - com.intellij.psi.tree.IFileElementType cannot be cast to com.intellij.psi.tree.IStubFileElementType
java.lang.ClassCastException: com.intellij.psi.tree.IFileElementType cannot be cast to com.intellij.psi.tree.IStubFileElementType
at com.intellij.psi.impl.source.PsiFileImpl.calcStubTree(PsiFileImpl.java:976)
at com.intellij.psi.stubs.StubIndexImpl$1.perform(StubIndexImpl.java:239)
at com.intellij.psi.stubs.StubIndexImpl$1.perform(StubIndexImpl.java:220)
at com.intellij.util.indexing.ValueContainer.forEach(ValueContainer.java:60)
at com.intellij.psi.stubs.StubIndexImpl.process(StubIndexImpl.java:220)
at com.intellij.psi.stubs.StubIndexImpl.get(StubIndexImpl.java:194)
at com.intellij.psi.stubs.AbstractStubIndex.get(AbstractStubIndex.java:33)
at com.intellij.psi.impl.java.stubs.index.JavaAnnotationIndex.get(JavaAnnotationIndex.java:47)
at com.intellij.psi.impl.search.AnnotatedElementsSearcher.a(AnnotatedElementsSearcher.java:93)
at com.intellij.psi.impl.search.AnnotatedElementsSearcher.execute(AnnotatedElementsSearcher.java:44)
at com.intellij.psi.impl.search.AnnotatedElementsSearcher.execute(AnnotatedElementsSearcher.java:28)
at com.intellij.util.ExecutorsQuery.processResults(ExecutorsQuery.java:42)
at com.intellij.util.AbstractQuery.forEach(AbstractQuery.java:67)
at com.intellij.util.InstanceofQuery.forEach(InstanceofQuery.java:54)
at com.intellij.execution.ConfigurationUtil.addAnnotatedMethodsAnSubclasses(ConfigurationUtil.java:97)
at com.intellij.execution.ConfigurationUtil.findAllTestClasses(ConfigurationUtil.java:77)
at com.intellij.execution.junit.TestPackage$MySearchForTestsTask.run(TestPackage.java:397)
at com.intellij.openapi.progress.impl.ProgressManagerImpl$TaskRunnable.run(ProgressManagerImpl.java:469)
at com.intellij.openapi.progress.impl.ProgressManagerImpl$2.run(ProgressManagerImpl.java:178)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:218)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:169)
at com.intellij.openapi.progress.impl.ProgressManagerImpl$8.run(ProgressManagerImpl.java:378)
at com.intellij.openapi.application.impl.ApplicationImpl$6.run(ApplicationImpl.java:434)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
at com.intellij.openapi.application.impl.ApplicationImpl$1$1.run(ApplicationImpl.java:145)
OK, I fixed it.
In menu, under File, there is an invalidate cache option. That fixed it!
On the latest IDE (as of Community Edition 2016.1) this option is more simplified.
right click on the folder you want to be recognized as a source folder:
Mark Directory As -> Sources Root
For some reason Intellij Idea don't recognize classes as Test class that are not explicitly public, in case class has default access specificator it will not be marked as a test. Try to change class to meet this rule.
Example:
public class TestMe {
#Test
public void shouldTest(){
Assert.assertEquals("test", "test");
}
}
Just to add a different scenario, which happened to me and some of my coworkers:
Alt+enter in the class -> create test: IJ (2017.1.1) proposes Arquillian Junit as first option of testing library and by going with it the test class and methods are created without the 'public' identifier. Then if one decides to change the testing library to JUnit, it is easy to forget about the absence of the 'public' identifier, which causes the tests not to be recognised by IJ. Of course, the solution is to place the 'public' identifiers.
Although this is not what happened to you it has the same consequence, therefore this answer may help others experiencing the same symptoms.
Fixed this a few times by... open file --> project structure. There, look on the left side menu as last entry there is "problem" count(if more then zero). click on those and then for for each problem highlighted in red in intellij in modules/libraries, remove them (minus button). They will be given module names like "test1..23" since intellij cant make out the structure. After deleting all marked red, close + restart intellij. Dont run maven refresh at this stage, since it will reintroduce the same error again. By restarting intellij will trigger a new scan of the project structure again.
In my case, we are moving from JUnit 4 to JUnit 5 and I mixed the #Test of them.
In short:
if you use #RunWith() of JUnit 4, you must use #org.junit.Test to annotate test methods.
if you use #ExtendWith() of JUnit 5, you must use #org.junit.jupiter.api.Test instead.
When I change the import, my class can be run as test class again.
None of the previous answers worked for me in IDEA 2019.1.2 (or -.3) with Junit Jupiter 5.5.0. I had git-cloned a couple of projects that I had pushed to GitHub from a different computer, where their tests ran fine. On my new laptop, I got "No tests were found" no matter how I tried to run them.
What finally did work: I deleted the IDEA-generated test.iml file, because I had noticed there was no such file in a virgin project I had created just to see if I could run tests at all (I could indeed). After I deleted this file in both older projects, tests ran perfectly. No new test.iml was generated.
I don't know how or when those files got generated. Because the git repos are private, I didn't bother to gitignore IDEA's *.*ml files; nevertheless, they weren't in the GitHub repos. Furthermore, they were at the roots of the projects, not in the .idea directory.
I ran into this issue with Ubuntu 20.04, Java 11.0.8-zulu, and Intellij 2020.2.
Upgrading Junit from 5.5.2 to 5.6.2 and Junit Platform from 1.5.2 to 1.6.2 solved it for me.
That seemed odd to me, so I switched the versions back, which now also works. I think some sort of cache invalidation is likely the best explanation, albeit the corresponding button for this didn't work for me.
So basically, what is said here https://stackoverflow.com/a/58687202/6476706 (I tried to comment there but can't...).
Anyway, still an issue in 2020, maybe this helps someone.
For me it was that the class being tested was not public. Once I set it to public the green run test icons popped up. Note, this is only an issue in Junit 4.
In my case I had to:
close the project
open the build.gradle file
overwrite existing project? Yes
right click on project
Mark directory as > Resources Root
Have a try changing a JUnit dependency version. One release forward or backwards. It can help invalidate test cache.
If you use a dependency management tool such as Maven or Gradle, go to the .pom or .gradle file and change the version of the JUnit library.
For instance change 4.11 to 4.12 or 4.10 in the version section:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<!-- change here -->
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
I ended up manually categorising every sources root and test sources root in all the modules for the project. Worked like a charm.
If you are using IntelliJ for test execution and debugging, but not for editing. Your other editor/IDE may be battling with IntelliJ for control over generated files (*.class) -- resulting in IntelliJ reporting that No tests were found (and maybe spurious build errors too).
In my case, Visual Studio Code seem to be having this effect (after recent updates to both tools).
The solution that I have found is to close Visual Studio Code and then clean rebuild the project with IntelliJ or from the command-line. In otherwords, my dual-IDE workflow no longer works -- so I have to edit in IntelliJ.
A poor workaround for this is to let IntelliJ run tests instead of Gradle.
File > Settings > Build Tools > Gradle > Run Tests With > IntelliJ Test Runner
This is a similar issue with another test framework on Gradle. https://youtrack.jetbrains.com/issue/IDEA-221159
I had a similar problem. After spending some time I found that I have created my class itself under the test root :-)
When I moved the class to the main root, everything worked fine for me :-)
Just been playing around for the first time with IntelliJ IDEA Community edition, first time I have worked with it so if I'm missing something, please excuse me.
I have a bunch of unit tests which I run, however, when running them in IntelliJ (with the standard setup out of the box), I intermittently get the following error in the console:
03:14:17 Failed to start: 58 passed, 1 not started
I have searched the web but to no avail. If I run just the test that failed, it may or may not print out a similar error:
03:19:54 Failed to start: 0 passed, 1 not started
If I keep trying, eventually it works and tells me that all of my tests have passed.
The image is not the error as an exclamation mark, it is a different error icon (), which I do not recognise. The error in Event Log window appears as red text.
It always appears to happen with only one test and it is always the same test for any given set of tests. I.E. In a different project, the same issue also appears, but for a different test (but it's always the same one in each project or set of tests).
One more thing to note is that this ONLY happens when debugging and not when running, so it may be something to do with connecting the debugger?
It all works perfectly fine with Eclipse.
Any ideas what could be causing this?
The issue for me is Failed to start: 1, passed: 0 . I'm using Spring Boot 2.4.0 with Junit5 to test the Controller Class. I just commented out the version tag in the junit-jupiter-engine dependency. Then it worked. Really strange. It might helpful for someone.
I got the same error. It was something weird sent to System.out that made IntellJ IDEA test "not started".
I've created a ticket for IntelliJ IDEA, you can vote for it if you still encounter this problem.
In my case problem was in pom.
I moved from fulling working application to spring-boot implementation and only imported spring-boot-starter-test in dependency for testing.
I solved by excluding junit part from spring-boot-starter-test and added junit dependency of latest version in separate block.
Sometimes similar error happens with scala code when you mix sclamock's MockFactory with scalatest's AsyncFlatSpec.
So, be sure to use AsyncMockFactory like below.
class ExampleSpec extends AsyncFlatSpec with AsyncMockFactory
Looks like this may have been a bug on IntelliJ, it has been raised with them.
I had this problem (in Android Studio but its a customised IntelliJ) and the reason was WHERE the cursor was when I ran tests using CTRL-SHIFT-F10.
#Parameterized.Parameters
public static Collection data()
Once I moved the cursor into a test method or not inside any method, it worked.
I had the same issue. Whatever be the number of scenarios, it was showing 1 extra scenario in NOT STARTED stage. I was using Scenario Outline to run tests and had commented the rows in the Example tables.
I later found out that commenting the whole example table (which I didn't wanted to run) resolved the issue rather than commenting each row.
I had the same issue that cracked me up a little in IntelliJ IDEA 2017.2.1. The test case ran without any recognizable errors or irregularities, but in the end JUnit claimed the case as not started.
Figured out it was caused by trying to print into a PrintWriter that has already been closed.
In my case I was trying to mock a class having a public static method. Problem solved when everything is set free from static context.
I came along not started tests, when attempting to test code that called System.exit(1) . IntelliJ would not start my tests until I removed the exiting behavior like this:
At first I replaced all direct lines in the code from
System.exit(1)
to
onFailure.run();
with
unnable onFailure = () -> System.exit(1);
in the code itself. In the Test-Code I replaced the Runnable with a testable mock Runnable
Runnable mockOnFailure =
() -> {
throw new CustomError(
"Some descriptive message here.");
};
and than I expected that Error to be thrown like so (using AssertJ for nice assertion statements)
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
assertThatExceptionOfType(CustomError.class).isThrownBy(
() -> {
callingCodeThatCallsOnFailure();
}
);
Now the tests are all being startet by the IDE as desired.
Feel free to reuse that if it is of help to you. I do not claim any ownership or copyright to any of those lines of code.
So I've been making a grammar in Eclipse with ANTLR v3.4 and I've made one that works and I want to make sure when I edit it everything still works. I can go into the interpretter everytime but that seems like a huge waste of time.
Questions:
I've read about gunit but the link it gives to download gUnit:
( http://antlr.org/hudson/job/gUnit/org.antlr$gunit/lastSuccessfulBuild/ ) doesn't work. How can I get gUnit.
What is the best way to test grammars? Is it actually gUnit or should I just do java tests like jUnit tests?
The question is old, but I'm leaving a reference for completeness:
For me, the gUnit was useless. So I managed to find how test only the Lexer and then, only the parser.
I answered it here: https://stackoverflow.com/a/53884851/976948
Basically, there are links for 2 articles about how to test it:
Unit test for Lexer
Unit test for Parser
I recently completed two ANTLR3 assignments (I'm working on my Master's in Computer Science) using Eclipse. I found no single document that had a process for installing, configuring, writing, and debugging a grammar in Eclipse. So, after working through various issues, I found the easiest thing to do was to stay in Eclipse for testing.
To use the process I have come to use (outlined below) you must first have the ANTLR IDE v2.1.2 installed. Add it right from inside Eclipse Indigo: http://antlrv3ide.sourceforge.net/updates. This site also has some useful doc on using the ANTLR IDE. Once installed, the IDE has to be configured. Video tutorials are a bit out of date but helpful. See a detailed how to guide on configuring ANTLR IDE in Eclipse. The main configuration item is the java output folder. Do this in Eclipse by going to Windows, Preferences, ANTLR, Code Generator, check Project relative folder and in the Output folder name box type a folder name (mine is called "antlr-java", others use "generated").
Test/Debug Process for ANTLR in Eclipse Indigo with ANTLR IDE
After a new project is created, right-click it, select Configure, Convert to
ANTLR Project...
Create the grammar in a .g file and save it. Note: filename has to match grammar name.
If there are significant errors, debug the grammar. Eclipse shows the ANTLR error(s)
and what line(s) are affected. At first, these errors seem hard to understand but
they can be worked through by using various resources:
- The Definitive ANTLR Reference by Terence Parr the guy who wrote ANTLR
- the ANTLR Reference Manual
- google the error; many times you will end up here at stackoverflow;
in particular, Bart Kiers is both knowledgeable and helpful (Bart: thx for
the help you didn't know you gave me)
On the first save after the serious ANTLR errors are resolved, the java output folder you
configured in Eclipse will be created and a java file in that folder will also be created.
Right-click on the java output folder, select Build Path, Use As a Source Folder. This
tells Eclipse where to look for the project's java source.
There are likely to be errors in the new java file. Select it, then search through looking
for java errors. Go back to your grammar or java file(s), correct the errors, and re-save
the grammar until both grammar and java files are error free, then run it.
From this point on, it's the usual modify-run-debug cycle.
The only other Eclipse change I needed was to create a few Run Configurations for testing
command line parameters.
You can download gUnit there but I think there is no latest version...
Try Jarvana... Latest version there is 3.4: http://repo1.maven.org/maven2/org/antlr/gunit/3.4/gunit-3.4.jar
#Dave Newton is right. As of ANTLR v3.1, gUnit is included in the main ANTLR Tool jar as is stated there.
I didn't know for gUnit till now. It looks great for grammar testing, but I think that JUnit tests will do their job to...
This is the first time I heard of gUinit and read up on it. (I don't use ANTLR much.) It sounds interesting, but half useless.
My approach to validating grammars is to actually validate the the entire parser with "normal" unit tests. The thing is, you should have unit tests in place anyway and the tests that check for grammar regression you just add it there. The thing is in my experience that most errors come in semantic analysis and reduction and not the grammar.