Visual Studio Code Java JUnit Not Outputting to Console - java

I am using Visual Studio Code with the java.home setting set to the directory of my JDK 11 installation. I have a Maven project and use 3.5.4 and have it added to my path, so I can run mvn in a console. Maven works as expected, as well as running the code's main method, however when I run a JUnit 4.12 test by clicking Run Test that is shown over an annotated #Test method, the test runs, however I am unable to view any console output from the JUnit tests.
Under Output, I have the Test Output window, which is where I would expect the console to output, however nothing shows up even though the test method runs System.out.println("test");
How would I go about making JUnit 4.12 display the test console output when a test is run by clicking the Run Test button shown over a test method?

This is currently a known issue in the plugin. The workaround is to disable the Maven plugin. (You can still use the terminal within VS Code to run Maven)

Related

In VSCode, how do I use Test Runner to run a Java JUnit test within the editor?

I have a Java project on VSCode for Windows and I have installed the Test Runner plugin ...
I would like to be able to run a test file from the editor and see the results. In Eclipse, I can right click on the test file but when I open the test file in the editor
I don't see any option to right click and run my test file and I don't see any "Run Test" text hovering above my test file class, as some other posts seem to suggest. What is the right way to run a test from the editor? I'm not tied to Test Runner for Java. I'm open to using other extensions.
The Test Runner for Java extension supports the following test frameworks:
JUnit 4 (v4.8.0+)
JUnit 5 (v5.1.0+)
TestNG (v6.9.13.3+)
You must first enable testing and adding test framework JARs to your project. Then in the Testing panel on the left, you can see the test list of the project and test it. A Test button is also displayed to the left of the test script.
There are more details you can look at this document.

NetBeans + TestNG -> "Go to source" is not possible

I have an huge maven project with TestNG tests. I create an new test file and add tests to it to clean my code out of bugs. I use NetBeans to run TestNG tests.
These are my issues:
The output of the tests is in text form. When I have got an stack trace, its elements are not hyperlinks (so they are not clickable). Rightclick + "Go to source" is also not possible. So I have to manually search for the class and the line with the error.
The output of the test is in text form, not like in this example: http://wiki.netbeans.org/TestNG
How could I get the stacktraces clickable?
P.P I use Netbeans 8.1.
Today I installed all pending plugin updates but the described behavior has not changed.
P.P.2 I start tests via Run -> Test File [Ctrl+F6]
This is related to two reported bugs in Netbeans.
#257563 - surefire 2.19.1 show no test results windows
solution: downgrade to surefire plugin version 2.18.1
#255883 - test results windows isn't displayed
solution: untick in the options Java -> Maven -> print maven output loggin level

How to run assertion test when JUnit view is empty in Eclipse

I've been following along a couple of tutorials and at the point where they run the tests in the junit test view in Eclipse, mine just looks disabled, and I can see any tests to run:
Notice on the right hand side I have an empty JUnit view. None of the tutorials mention anything about this situation. You can see the JUnit library in my Package Explorer too. What do I need to do now to get my test to run in the JUnit test view?
You got the project setup right, now you need to tell eclipse to execute the test cases locate in the project, for that you need to do the following
Right click project --> run as --> Junit Test
And the Junit view of the eclipse will get populated with the test runs as below with the results of which cases failed and which passed
Just right click on AssertTest.java; then follow below--
run as > Junit Test
Since looking into your screen shot, you only have one Junit class; so it seems this will help you to run Junit.
I found this post while looking into a slightly different "empty JUnit view" issue: after upgrading to Eclipse 2022.06 from 2021.??, my JUnit view stopped working. I could see the unit tests running in the console, but no results were shown in the view.
I was able to fix it by opening the Eclipse preferences Java -> JUnit, then clicking Apply and Close.

IDEA Play 2.4 junit test without full sbt build

I want to run JUnit tests for my Play 2.4 application within Intellij IDEA 14.1.4 to leverage full JUnit integration.
The tests are executed fine when I create a new JUnit run configuration. However on every test run a full SBT build is executed delaying the tests for around 30 seconds.
If I remove Make form the pre-launch steps in the JUnit run configuration the tests are executed directly without a full sbt build but then any code changes in test and application code are not picked up by IDEA. Even when the play is running with auto-compile on file changes IDEA doesn't pick them up for the tests.
Edit 07/09/2015
I've also exchanged Make with an SBT Action test:compile which only opens up a SBT console loading the project and stops with a prompt. It's not executing the action test:compile and therefore not starting the test at all.
What do I have to change in run configuration and/or project settings to get a fast and seamless JUnit integration for Play projects in IDEA?
Finally found the answer myself when digging through issue tickets of idea-sbt-plugin.
Exchanging Pre launch Step Make with SBT Action test:compile was the right way to go. However the SBT Plugin expects the default sbt shellPromt >. Play projects however define their own custom promt as [projectname] $.
I had to add the following line to build.sbt to get the SBT action to work.
shellPrompt := (_ => "> ")

Eclipse Kepler (4.3) JUnit (3.81) view not showing test results, using code created by maven-archetype-quickstart

Getting back into Java coding after being away for a while, downloaded the latest Maven (3.1.1), the latest Eclipse (Kepler), the latest JDK (1.7.0_45), created a new Maven project in Eclipse (using the quickstart archetype, which looks like it defaulted to JUnit 3.8.1), opened AppTest.java, selected "Run As JUnit Test" (not JUnit Plug-in Test), and nothing shows up in the JUnit view.
Shouldn't it at least say something like "Runs: 1/1"? If I change the code in testApp() to "assertTrue( false)", then I don't see a failure (although if I debug, sure enough, an exception gets thrown). If I put a println() in the test, I see its output in the console view. If I run mvn test from the command line, I get a lovely stacktrace and the word "FAILURE!" (and my println() output).
So. Something basic is wrong somewhere, but what?
Maybe you checked the "Show Failures Only" option? (on the same bar as "Rerun Test"). It happened to me :)
I think I repeat your problem. It happens when the JUnit window is opened initially in eclipse (for example I detached the view as separate window and it shows when eclipse starts).
With fresh start (window/view shown) I run tests and don't see anything in it, when I close it and run unit tests (via 'run as') window reopens but now results are shown.

Categories