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.
Related
I am facing a strange issue, while debugging the Unit Test, i put a break point at unit test API (Test_Computation) and another break point at the concrete class ComputationImpl::Computation() which invoked from Test API. While debugging, getting the below issue:
Unable to install breakpoint in com.lok.ComputationImpl$$FastClassByGuice$$983a053 due to missing ine number attributes. Modify compiler options to generate line number attributes. Reason: Absent Line number information
But the TestClass break point is hitting, not the actual class.
I am using amazon correto 1.8, eclipse 2020 (latest).
I followed all options here, but did not help me.
Eclipse - Unable to install breakpoint due to missing line number attributes
Can someone please help on this.
The issue was due to a wrong Mock on class. Its resolved now
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
I am using the gradle-cobertura-plugin in my Jenkins-build. Yesterday I fixed an issue in this plugin that overwrote the configured auxiliaryClasspath. This issue prevented some classes being present in the coverage report. The fix is something quite simple:
I changed the following:
auxiliaryClasspath = project.files("${project.buildDir.path}/intermediates/classes/${classesDir}")
to
if (auxiliaryClasspath != null) {
auxiliaryClasspath += project.files("${project.buildDir.path}/intermediates/classes/${classesDir}")
} else {
auxiliaryClasspath = project.files("${project.buildDir.path}/intermediates/classes/${classesDir}")
}
Running the build locally with gradle cobertura everything works fine and the missing classes showed in the report.
After installing the patched version of the plugin on Jenkins the coverage on Jenkins went to zero.
Looking around what happened I found that the classes in the instrumented_classes-folder are not instrumented anymore! Rolling everything back (build.gradle, uninstalling my plugin, clearing the gradle cache, etc.) the behaviour stays the same. As it is working locally I'm wondering what causes this issue.
I assume there is something going awefully wrong that's perhaps logged and silently ignored, but I don't have a clue where to look for this information. The Jenkins logs are clean, so I think adding a logger for the code responsible for instrumenting might help. Unfortunately I don't have any idea what loggers to enable. org.sourceforge.cobertura didn't output anything.
So my question is: Did anybody else see this behaviour and might throw in a clue how to resolve this issue?
OK, I figured it out. After much trial and error I found that a little change in the coverageExcludes-property was the culprit. After changing it several times the classes are instrumented once again. Funny that it did work locally but not on jenkins. I think I have to dive a little bit deeper in this if it occurs again.
For now I'm happy that it works. :-)
During debugging the test code it hangs on the initialization phase.
The latest message at the log is (before the debugging hangs):
2013-03-15 13:03:09:215 INFO [ : ] [main:o.h.d.Dialect] Using dialect: my.company.package.util.hibernate.HSQLDialect
Please consider the following factors which seems to impact the debugging:
Test runs with #RunWith(SpringJUnit4ClassRunner.class)
Test run on IntelliJ IDEA 12.0.4
When tests run without debugging they works without any problems
What to do to debug the code?
Make sure you did not place a breakpoint on method signature instead of line of regular code. You can recognize such breakpoint also by 4 black dots inside red circle. They slow down debugging dramatically.
Try to remove all breakpoints and restart your Debug.
Press Command+Shift+F8, then Command+A and press Del. This if for Mac.
It could easily be that you need to supply the test with more PermGen space.
Try using this in your configurations for that test:
-XX:MaxPermSize=300m
If your tests aren't insanely huge (and they shouldn't be), this should be more than enough.
I get on my local machine the following exception when running the tests by maven (mvn test).
ch.qos.logback.core.joran.event.SaxEventRecorder#195ed659 - Parser configuration error occured
java.lang.ClassCastException: com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl cannot be cast to javax.xml.parsers.SAXParserFactory
After googling around I came across several pages which describe the main problem behind it (several SAXParserFactoryImpl in different classloaders).
-> http://www.xinotes.org/notes/note/702/
My question is, how can I figure out which library is also providing the SAXParserFactoryImpl, so that I can exclude it. I am using Maven, IntelliJ and JDK 1.6.0_23. The issue occurs on the command line as well as when running the tests from IntelliJ.
But the strange issue is, that on the build server this issue doesn't occur.
Update 1
Just figured out when I run the first time mvn test after an mvn clean, the error doesn't appear. But as soon as I run mvn test again (without clean, the exception occurs) (when I run it from IntelliJ).
When I run it on the cmd line, then several mvn test calls do work.
I found the issue. It was related to PowerMockito who tried to load the SAXParserFactory. The reason why I haven't figured that one out was because the stacktrace contained only twice PowerMockito, and this at the middle :-)
So If you figure out this problem in IntelliJ and you do use PowerMockito, annotate your test class with the following annotation:
#PowerMockIgnore(["javax.management.*", "javax.xml.parsers.*",
"com.sun.org.apache.xerces.internal.jaxp.*", "ch.qos.logback.*", "org.slf4j.*"])
This has solved the problem in my case.
Your JDK probably has its own SAXParserFactoryImpl.
Check for jars like xercesImpl, xml/xml-api and sax.
One your server the one from the server is probably going to be used.
You can use a jarfinder: http://www.jarfinder.com/index.php/java/search/~SAXParserFactoryImpl~
I encountered the same error today. After a lot of digging, I found that the solutions here, or on other places are not helpful.
However, after playing around, I found a solution that works deterministically, unlike the accepted answer which does not apply to all cases.
The answer is, look through stack trace to find any ClassCast exceptions, and just add them to \#PowerMockIgnore list. Keep repeating until the issue is solved. Worked like magic for me.