When I run the my unit tests, they immediatly are being terminated. However no logging is presented. (only 'Failed to start' and 'Process finished with exit code 255').
Tests worked before...
JUnit 4 does not give me this problem.
Test do run succesfully in Maven.
I use JUnit5 Jupiter and IntelliJ IDEA 2020.1 (Ultimate Edition).
Anyone any thoughts?
I was experiencing the same behaviour as described in this question. What fixed the problem for me was removing conflicting dependencies:
Remove similar entries ->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.2.0</version>
</dependency>
as it is already included by spring-boot-starter-test. Removing the explicit dependency will enable SpringBoot to handle incompatible version issues between dependencies for you.
#Before and #After no longer exist; use #BeforeEach and #AfterEach instead.
#BeforeClass and #AfterClass no longer exist; use #BeforeAll and #AfterAll instead.
https://junit.org/junit5/docs/current/user-guide/#migrating-from-junit4-tips
I just had the same issue.
The single thing that fixed this - and which I could reproduce - is this:
don't .close() System.out (or System.err).
#Test
void failure()
{
System.out.close();
}
makes happen what you describe.
Wherever I passed System.out to functions that would .close() their OutputStream later, I replaced them with a new ByteArrayOutputStream() instead.
After experiencing the same, I've debugged only to find that tests are completely executing and all assertions pass.
I've managed to narrow the issue down to System.out.println call whose output is somehow being held until all the tests are complete before, and eventually flushed, before IDEA gets to claim that test was interrupted.
Removing a reference to System.out from test code makes the tests go green in IDEA again.
For me using #BeforeEach and #AfterEach worked instead of #BeforeAll and #AfterAll
Related
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.
I am running IntelliJ IDEA 2018.3.1 and am attempting test a class with the integrated test runner. The test seems to compile but not run.
This is a multi-module Maven project, and other modules have tests that run. However, I have not been able to find any differences between the projects. The surefire plugin is specifically defined on this project, and <skipTests> is specifically set to false. I have reimported the project several times in case the maven configuration is affecting the built-in runner.
The image below is the only output I get. Debug/Breakpoints will not stop.
If anyone can help or throw possibilities at me, I would appreciate it.
Edit:
Here's a simplified version of the test I'm attempting to run:
package com.jason;
// imports
#RunWith(BlockJUnit4TestRunner.class)
public class MyTest {
private ClassUnderTest clazz;
private DaoClass dao;
#Before
public void setUp() {
// using Mockito to mock the DaoClass
// injecting the DAO into the ClassUnderTest
}
#Test
public void testMethod() {
Assert.assertTrue(true);
}
}
I attempt to run the test by right-clicking on the method annotated with #Test and clicking run. The option to run the test DOES appear in the context menu. When I do so, all that appears is the screenshot.
I have attempted to do the following to troubleshoot the issue:
In the pom.xml file for the appropriate module, I have manually specified the surefire plugin in the <build><plugins> section. I then did a reimport to pick up the changes.
I have put breakpoints in the code and run the test in debug mode.
I have attempted to log output, both with an slf4j logger and a System.out.println()
I have attempted to find any differences in the IDEA .iml file between a module where the tests run and this module where the tests do not run.
I have written a very simple test class, with a method annotated with #Test and containing the line Assert.assertTrue(true)
Edit 2
Attempting to run mvn test -Dcontrollername produces the following output:
Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project rma-svc: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test failed: The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
Edit 3
I've updated my Maven surefire plugin to 2.22.2 and am not seeing the forked JVM issue any longer. However, running mvn test -DskipTests=false outputs No tests were executed!
I get a NoSuchMethodError on AssertJ when I try to execute a unit test. The make step works fine and when navigating to the implementation of assertThat(), it works just fine.
The module dependencies show that I am using org.assertj:assertj-code:1.2.0 as I have defined as compile dependency in my build.gradle (yes, compile and not test). The unit test resides inside the main classpath of my module since it is an integration test, so this is intentional. The iml file contains:
<orderEntry type="library" name="Gradle: org.assertj:assertj-core:1.2.0" level="project" />
My example test is:
import org.assertj.core.api.Assertions;
import org.junit.Test;
public class X {
#Test
public void x(){
Assertions.assertThat(1).isEqualTo(1);
}
}
and when I execute it, I get:
java.lang.NoSuchMethodError:
org.assertj.core.api.Assertions.assertThat(I)Lorg/assertj/core/api/IntegerAssert;
When I look in the run configurations, the classpath is set to the correct module (the module containing AssertJ).
I have tried invalidating caches but that did not help.
I am currently out of ideas (no pun intended).
Anyone out there who has seen this before? Or have a clue on how to proceed troubleshooting?
Found it.
I had another module importing a newer version of AssertJ. And somehow (seems like a bug in IntelliJ) my runtime was using that one instead.
I will keep track of my reported bug: https://youtrack.jetbrains.com/issue/IDEA-156718 and post updates.
I'm using Jenkins with FindBugs plugin installed for static code analysis. Also, every developer on the team have FindBugs IntelliJ IDEA plugin installed to do the same.
The problem is that in Jenkins, only first occurence of an error in a method is reported. In Idea, all problems are reported as single errors. For example:
public String myMethod() {
StringBuilder sb = new StringBuilder();
sb.append(String.format("First \n"));
sb.append(String.format("Second \n"));
sb.append(String.format("Third \n"));
sb.append(String.format("Fourth \n"));
return sb.toString();
}
in this method, Idea reports 4 errors of type VA_FORMAT_STRING_USES_NEWLINE. On jenkins server, there is actually only one error, on line with string First \n.
Is there a way to configure either Jenkins or Idea to behave uniformly?
Versions:
IntelliJ Idea Enterprise 12.1.3
FindBugs-IDEA plugin 0.9.97
Jenkins 1.513
Jenkins findbugs plugin 2.0.2
The only solution I've found so far is to use a different plugin, eg. QAPlug Findbugs. This one reports results exactly the same as Jenkins does.
The downside is it is a bit more clumsy than FindBugs-IDEA plugin.
We are using arquillian-junit-container 1.0.0 final version for Junit Test.
We have so many test classes and every test class as #Deployment method so when i run all test together then its creating issue of memory and performance.
Can anyone help me to sort out this issue by telling how we can avoid multiple deployment for each single class. How we can achive Single deployment for all test cases in Arquillian?
You can't, officially, yet.
The JIRA issue ARQ-197 was created to support running multiple tests classes against a single deployment. In 2010! If you want this feature, please vote for it.
This is Arquillian's most voted for issue. It's currently slated for version 2.0.0.CR1, which might be the next version, but I can't find a roadmap / release plan anywhere which confirms this.
In the meantime, there is the Arquillian Suite Extension (latest incarnation is here). It's not official, and so there are limitations, but the original codebase was written by one of the Arquillian core developers to prove they could eventually support JUnit suites. The issue to make this support official is here and is Arquillian's second-most voted issue.
I think you're asking why does Arquillian need to deploy a new war for each test class when you run the test. I have the deployment method as Petr Mensik describes, but each test class will still deploy in it's own war when you run the tests. Putting it in the super class only simplifies the code from a less lines perspective. It will mean that every test class that is sub class will have the same deployment. That means your deployment will be the super set of dependencies, and thus much larger than doing it individually. I think it's easier to manage, and worth the price especially with larger projects.
To answer your question, it looks like you will not be able to group your tests and deploy one war to test until version 2.0 (due out at the end of this year?).
Why should you have deployment method in every class?I use Arquillian for functional testing with Drone and Graphene and I have one base class with deployment method, initialization of Selenium Web Driver, few utils methods and my every other test class is just extending this class and reusing my Web Driver instance.
I don't see why shouldn't this work in your case (or even without extending the base class).
Ok, this is how it looks
public class WebDriverTest extends Arquillian { //I am using TestNG
#Drone
protected WebDriver driver;
#ArquillianResource
private URL contextRoot;
#Deployment(testable = false) //functional tests cannot run in container
public static WebArchive createDeployment() {
File archive = new File("target/myApp.war");
ShrinkWrap.createFromZipFile(WebArchive.class, archive);
}
}
public class TestClass extends WebDriverTest {
#Test
public void test1() {}
#Test
public void test2() {}
}
Everything is working fine here. Also make sure that you have right Maven dependencies, these has to be present in order to run functional tests (then make dependency for anything you need from these BOMs)
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.selenium</groupId>
<artifactId>selenium-bom</artifactId>
<version>${selenium.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>${arquillian-core.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-drone-bom</artifactId>
<version>${arquillian-drone.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
EDIT
Ok, so according to this JIRA you won't see this feature in Arquillian until version 2.0.0.CR1. So the code I mentioned above is the best you can get right now:-)