Java on Visual Studio Code Update – January 2021

Yaojin Yang

Yaojin

Welcome to the first edition of VS Code update for Java in 2021. We got some questions around how to run tests on VS Code, so in this blog we will walk you through the how. Meanwhile, we will share the news of releasing Azure Spring Cloud extension. The extension is for you to create, manage and deploy apps to Azure Spring Cloud, a fully-managed Azure Service jointly built and operated with VMware. Let’s start.

Testing

To run Java tests on VS Code, we recommend using Java Test Runner extension. Our Java Extension Pack also includes the extension. The extension support JUnit4, JUnit5 and TestNG frameworks.

Running tests

When a project with test cases imported into VS Code, VS Code can automatically detect the test cases and get ready for you to run. There are a couple of options to run.

1. Running from Test Explorer

Test Explorer offers the most comprehensive support for testing. In addition to run cases individually, you can Run All Tests as shown below.

Image test explorer running test2

2. Running from JAVA PROJECT Explorer

JAVA PROJECT Explorer provides access to all project related functionality including testing. You can run tests at project level or at individual package or class level as demonstrated below.

Image project manager running test2

3. Running from CodeLens

CodeLens is a VS Code feature that provides context-aware actions through link next to your code. When VS Code detects testing annotation in code, it will provide a link of “Run Test” and a link of “Debug Test” next to the annotation for you to quickly place an action without jumping out of your code. It’s a handy feature that allows you focusing on coding by minimizing context switch.

Image code lens running test

Accessing testing report

After running tests, VS Code generates a testing report for you. You can access the report through status bar as shown in demos above or using Command Palette by Ctrl+Shift+P to launch the palette and then typing “java show test report” to open the report.

Azure Spring Cloud extension and more

Microsoft just released Azure Spring Cloud extension. The extension is for you to create, manage and deploy apps to Azure Spring Cloud, a fully-managed Azure Service jointly built and operated with VMware. The release underlines that VS Code is not only good for tasks like editing, running, debugging and testing, but also provides a seamless end-to-end experience for working with services. For Java developers on Azure, extensions are also available for other services like Azure App Services, Azure Functions, and many more. Please refer to VC Code documentation for more details. Meanwhile, we welcome communities and companies to develop extensions for your services. Let us know if you need support.

Enhancements

  • VS Code Java now supports referring envFile in launch.json for debugging.

Image envfile

  • JAVA PROJECTS explorer now supports displaying file decorator just as File Explorer.

Image file decorator

Try it out

Please don’t hesitate to give it a try! Your feedback and suggestions are very important to us and will help shape our product in future.

3 comments

Comments are closed. Login to edit/delete your existing comments

  • Hello, World!
    Hello, World!

    Можно использовать котлин на vs code

  • Arturo Cerecero
    Arturo Cerecero

    Hello,

    I’m starting on automated test and recently connected my framework with a azure devops pipeline to run the test cases. Now I’m trying to connect the execution to the test plan that we have. Is this possible or am I trying to do an impossible here?

    Thanks for the guide!

    • Yaojin Yang
      Yaojin YangMicrosoft employee

      Hi Arturo, we would like to learn more details about your scenario. Would be possible for you to file a issue here? We can discuss further using the issue thread.