Hi everyone, welcome to the March update for Visual Studio Code for Java! In this blog we are going to share several new Spring Boot features as well as testing coverage updates, so let’s get started!
Spring Boot Feature Updates
New Refactoring Preview available for version upgrades
The feature to automatically upgrade your projects to the latest Spring Boot version now allows you to choose between applying those changes directly to your project or previewing them in a refactoring preview. The refactoring preview gives you an exact diff for all the changes that the automated version upgrade process produced and allows you to select which changes to apply and which not. Please note that currently all changes are unchecked, so you need to select the changes you want to apply manually.
To refactor Spring Boot projects or upgrade Spring Boot projects to a newer version, you can directly right click on the POM.xml in your Spring Projects in Visual Studio Code, and click on “Refactor Spring Boot projects” or “Upgrade Spring Boot projects“, here’s how to do it.
You can also watch this short video for the full demonstration of all the features.
Changing Log Levels on the fly
The Spring Tools in Visual Studio Code show live information from a running Spring Boot application if you have actuators on the project classpath and start your app from within Visual Studio Code. The latest update adds viewing and changing log levels to this. A command in the palette (>Spring Boot: Set Log Levels) lets you select the running Spring Boot application, search through the list of active log levels, and allows you to change them directly within the running application. The change is effective in the running application only. The next time you start your app, the default log level settings are back.
Add Spring Boot Starters right from within your pom.xml file
There is a new link showing up in the dependencies section of your pom.xml file that allows you to directly invoke the command to add additional Spring Boot starters. We hope this makes it much easier to access add Spring Boot starters directly from POM.xml.
To see all these new Spring features above, please install the Spring Boot Extension Pack.
Testing Coverage available in Stable Version of Visual Studio Code
We’re excited to announce that developers can now run tests with coverage in the Stable version of Visual Studio Code! This feature was previously enabled in the Insiders of Visual Studio Code and we’ve been fine-tuning it since then. To use it, developers just need to go to the testing panel as usual, and click the new “Run Tests with Coverage” button. Underneath this feature, the report is generated by the Jacoco library and visualized by the latest Testing Coverage API from Visual Studio Code.
To use Testing Coverage, make sure you upgrade to the latest version of Extension Pack for Java.
Coverage information is shown as an overlay on line numbers by default, but you can Toggle Inline Coverage to see complete detailed information for your source files:
You can refer to previous blog posts for more feature demos (December 2023 blog post and January 2024 blog post)
Install Extension Pack for Java
To use all features mentioned above, please download and install Extension Pack for Java on Visual Studio Code.
If you are a Spring developer working on a Spring Boot application, you can also download the Spring Boot Extension Pack for specialized Spring experience.
Feedback and suggestions
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
- Leave your comment on this blog post
- Open an issue on our GitHub Issues page
- Send an email to: vscjfeedback@microsoft.com
Resources
Here is a list of links that are helpful to learn Java on Visual Studio Code.
- Learn more about Java on Visual Studio Code.
Thanks for the test coverage feature and it looks great.
I tried two simple exercises, one works and one does not work as expected.
The “work” one is I tried to add a new test case and could see the test coverage increases as expected.
The “does not work” one is I tried to reduce test case (basically delete the new test case that I just added) and expect the test coverage will decrease accordingly, but it does not and stay at the same number. Can you check?
I tried to reset the test coverage but could not find a way to do so. In the source code, the covered lines stay the same even I removed the related test cases.
Thanks for your help in advance!
Hi Gerry,
Thank you for the feedback.
By default, the extension will append the coverage data (we use jacoco as the coverage tool, and jacoco appends the coverage data by default)
If you want to reset the coverage data before every coverage execution, you can set the below setting:
Thanks Sheng, it works like charm !
Hi Gerry,
These two are very practical cases, and we’ll take a look and provide updates