Easily enabling unit testing in basic Java projects
We have received a lot of feedback from students that when working on a simple Java project, they always have to manually add the testing framework JARs (such as JUnit) to the project, and our Java extensions does not offer any functionality to easily help them with this common task. To address this, we have added a new feature in our extensions so that if your project(assuming it is a basic project without build tools)does not contain any testing related libraries, you can easily add the JAR and enable unit testing in your project.
To use this feature, simply go to the “Testing” view and select “Enable Java Tests” (shown in the picture below).
This button will do two things for you:
Download the testing related JARs based on your choice (JUnit, JUnit Jupiter, TestNG)
Add the downloaded JAR to the libraries folder
Here is a demo of the feature:
After this step is done, simply create a Java file and start writing unit tests! You can get this feature in the latest update ofExtension Pack for Java.
Better support for GUI application development (JavaFX, Swing and AWT)
GUI-based Java applications are quite common in school projects. The most commonly used GUI frameworks are JavaFX, Swing and AWT. In this section, we are going to highlight some optimizations we have made to support these frameworks better.
We have added built-in support to create a JavaFX based project with Maven archetype in our Java extensions. To use this new feature, simply bring up the Command Palette(Ctrl+Shift+P)and run command “Java: Create Java Project“. From the drop-down list, select “JavaFX“. After selecting this item, a JavaFX project based on Maven will be created for you.
To run the JavaFX application, you can open theMavenview, expandhellofx > Plugins > javafx and run the Maven goal: javafx:run
More Visual Studio Code sample projects for JavaFX
We also realize students might be working on JavaFX projects using other build tools (Gradle) or no build tools at all, therefore we have provided complete JavaFX samples for all those different cases. Please find the latest JavaFX samples for Visual Studio Codein this sample repository.
Abstract Window Toolkit (AWT)
AWT is another framework that is popular among Java GUI application development. However, the types from the Abstract Window Toolkit (AWT) are hidden by default due to some constraints, therefore you may notice that code completion does not prompt AWT classes when you are working on an AWT application. To enable the code completion for AWT, you can open the Command Palette(Ctrl+Shift+P)and then select the command Java: Help Center. Go to the Student section and select Enable AWT Development. Please note that this action will update a setting at the workspace level, so please make sure a workspace is opened in Visual Studio Code. Here is a demo of this feature:
After the setting is enabled, code completion will work on AWT applications! You can usethis basic sample codeto test your AWT on Visual Studio Code.
Swing application development is supported in the Extension Pack for Java by default. You can directly develop any Swing application without additional setup. To find more Swing examples, you can visit theofficial Oracle documentation.
Documentation for Java GUI application development on Visual Studio Code
Apart from these feature updates, we have also addeda dedicated articlefor Java GUI application development on official Visual Studio Code documentation. We hope this article can help students and educators to easily get started on GUI development and set up the project.
New Gradle project creation workflow
In addition to unit testing and GUI applications, we are also seeing that Gradle is becoming more popular among students as well as professional developers. Therefore, we have added support for Gradle project creation in our Java project creation workflow. This feature will help you to bootstrap a simple Gradle project with just a few steps. To use this feature, simply bring up the command palette(Ctrl+Shift+P), then run the“Java: Create Java Project“, and select “Gradle” from the list. Currently this workflow supports bothGroovyandKotlinas your Domain Specific Language (DSL).
You can also click the “Create Java Project” button to use this feature.
There will be lots of exciting updates for Java on Visual Studio Code in 2022, and as always, your feedback and suggestions are very important to us and will help shape our product in future. There are several ways to give us feedback