Giter Club home page Giter Club logo

vscode-java-test's Introduction

Test Runner for Java

Run and debug Java test cases in Visual Studio Code

Overview

A lightweight extension to run and debug Java test cases in Visual Studio Code. The extension support following test frameworks:

  • JUnit 4 (v4.8.0+)
  • JUnit 5 (v5.1.0+)
  • TestNG (v6.9.13.3+)

Note: JUnit 3 styled tests are not supported in this extension (i.e. extends junit.framework.TestCase).

The Test Runner for Java works with Language Support for Java by Red Hat and Debugger for Java to provide the following features:

  • Run/Debug test cases
  • Customize test configurations
  • View test report
  • View tests in Test Explorer

Requirements

Features

Run/Debug Test Cases

Run/Debug Test Cases

  • The extension will generate shortcuts (the green play button) on the left side of the class and method definition. To run the target test cases, simply click on the green play button. You can also right click on it to see more options.

Test Explorer

Test Explorer

  • The Test Explorer is the place to show all the test cases in your workspace. You can also run/debug your test cases from here.

Customize Test Configurations

Customize Test Configurations

  • Sometimes you may want to customize the configuration to run your test cases. To achieve this, you can add the configuration into your workspace settings under the section: java.test.config.

Note: More details can be found here.


View Test Result

View Test Result

  • After running/debugging the test cases, the state of the related test items will be updated in both editor decoration and test explorer.
  • You can trigger the command Test: Peek Output to peek the result view.
  • You can click on the links in the stack trace to navigate to the source location.

VS Code Embedded Commands for Testing

VS Code Embedded Commands for Testing

There are other VS Code embedded commands for testing, which can be found by searching Test: in the Command Palette.

Settings

Setting Name Description Default Value
java.test.config Specify the configuration for the test cases to run with. More details. {}
java.test.defaultConfig Specify the name of the default test configuration. ""

VS Code Embedded Settings for Testing

VS Code Embedded Settings for Testing

There are some other VS Code embedded settings for testing, which can be found by searching testing in the Settings view.

Project Setup

JUnit 5

Please refer to Getting Started from the JUnit 5's official document for getting started documentation.

Note: If your project does not use build tools(Maven/Gradle/...), please make sure junit-platform-console-standalone.jar is on your project classpath.

JUnit 4

Please refer to Download and Install from the JUnit 4's official document for the getting started documentation.

TestNG

Please refer to TestNG Docs from the TestNG's official document for getting started documentation.

FAQ

If you meet any problem when using the extension, please refer to the FAQ and our issue list to check if there is an answer to your problem.

Contributing and Feedback

If you are interested in providing feedback or contributing directly to the code base, please check the document Contributing to Test Runner for Java, which covers the following parts:

License

This extension is licensed under MIT License.

Telemetry

This extension collects telemetry data to help improve our products. Please read Microsoft privacy statement to learn more. If you opt out to send telemetry data to Microsoft, please set below configuration in settings.json: telemetry.enableTelemetry = false. Learn more in our FAQ.

vscode-java-test's People

Contributors

akalirong avatar akaroml avatar alexaegis avatar ansyral avatar baermitumlaut avatar baronswindle avatar cscherryy avatar dependabot[bot] avatar dreamworld avatar eskibear avatar fladdimir avatar frederick888 avatar gayanper avatar hacke2 avatar jbelford avatar jdneo avatar jlink avatar kropie avatar michael-emmi avatar microsoft-github-policy-service[bot] avatar reubenfrankel avatar sandy081 avatar testforstephen avatar xqzlgy2 avatar yaohaizh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vscode-java-test's Issues

Provide switch to optionally show output window

Currently, we force showing output window whenever users run test cases. This could be disruptive when users are currently working on debug console or integrated terminal.

We can provide an option in user settings to allow switch that behavior on and off.

BI add eventid into err logs

We have three type of events: run test, debug test, show details. right now only perf data contains eventid, we'd better pass eventid into all the err/info logs that are recorded in the session of event.

JUnit 5 Support

As the java community progresses to use JUnit 5 instead of JUnit 4 please add support for JUnit 5 as well

0.2.0 Endgame

Build

Test

Release

  • 12/22 - Add 0.2.0 tag for vscode-java-test - @ansyral
  • 12/22 - Release to marketplace - @ansyral

Notes

Before you check an item, please reply to this issue with the following details:

  1. What are the steps and details of your check?
  2. What are the configurations?
  3. What are the issues found in the process?
  4. What's your conclusion?

Spring Boot integration test hanging test runner

I have a vanilla Spring Boot app, and when running the default integration test supplied the test runner just hangs in the "Running tests..." state. I can see that the tests actually execute by looking at the test output window, but it seems it never returns the state. Normal unit tests without spring context works 100%.

Sample Class:

@RunWith(SpringRunner.class)
@SpringBootTest
public class MyApplicationTests {

    @Test
    public void contextLoads() {
    }  

}

Support JUnit-dataprovider

Our tests make heavy use of https://github.com/TNG/junit-dataprovider. All of those are skipped. Furthermore, if I run all tests of a class (by clicking the Run Test button above the class declaration), even the plain JUnit tests are skipped as soon as the data-provided tests are encountered.

Are you planning on supporting the dataprovider package?

Correct color on status bar item

Now we use different colors to reflect different result state. And we need to change a bit:

  1. Running - default color (white)
  2. All passing - green
  3. 1 or more errors - red
  4. Initial (no results) - default color (white)

Class name is not set correctly

I'm trying to make this extension work, but the first letter of the class name is always cut off. The problem is depicted in these Pictures:

vscodejunitexplorer

vscodejunittest

The name of the Test is always missing the first letter of the class name, thats whats causing the error.
The class' name is "TestThis", but the name of the test that is being run is "estThis". This happens with every other letter too and i have no idea whats causing this.

JUnit itself works fine with this test, if i run it manually.

I have no idea what could cause this on my end and have not found any mention of this in other issues.

0.1.0 Endgame

Build

Test

Release

Notes

Before you check an item, please reply to this issue with the following details:

  1. What are the steps and details of your check?
  2. What are the configurations?
  3. What are the issues found in the process?
  4. What's your conclusion?

Test explorer

We need an explorer to show all the cases inside the current workspace.

Users should be able to run and debug test cases by right-clicking the tree nodes.

no icons

using the latest version it does not seem to show me the cancle/setting icon?

image

How to change default encoding in output

Error occured: ʮ���� 02, 2017 11:03:44 ���� org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
��Ϣ: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@532760d8: startup date [Sat Dec 02 11:03:44 CST 2017]; root of context hierarchy
Error occured: ʮ���� 02, 2017 11:03:44 ���� org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
��Ϣ: Loading XML bean definitions from class path resource [beans.xml]
����û�
LinkedHashSet
����
����

Junit starts from a different location

Hello fellows,

in a project with several files an including some integration tests, I am trying to perform the following actions:

File csFile = new File("src/test/resources/Program.cs").getAbsoluteFile();

Let's say that my project is in C:\temp\myproject therefore i will expect to get something like:

C:\temp\myproject\src\test\resources\Program.cs

but instead i got:

Caused by: java.nio.file.NoSuchFileException: C:\Program Files\Microsoft VS Code\src\test\resources
	at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:79)
	at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:90)
	at sun.nio.fs.WindowsLinkSupport.getRealPath(WindowsLinkSupport.java:259)
	at sun.nio.fs.WindowsPath.toRealPath(WindowsPath.java:836)
	at sun.nio.fs.WindowsPath.toRealPath(WindowsPath.java:44)
	at org.sonar.api.batch.fs.internal.DefaultInputModule.initBaseDir(DefaultInputModule.java:86)
	... 27 more

Is possible to setup the start folder for Junit?

NoClassDefFoundError: org/junit/runner/JUnitCore

I can run tests in a single module project, but as soon as I have multiple modules (e.g. opening up https://github.com/spring-cloud/spring-cloud-function/tree/master/spring-cloud-function-samples since that was what I was working on), I get this:

Error occured: Exception in thread "main" Error occured: java.lang.NoClassDefFoundError: org/junit/runner/JUnitCore
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
Error occured: 	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at com.microsoft.java.test.runner.JUnitLauncher.main(JUnitLauncher.java:20)
Caused by: java.lang.ClassNotFoundException: org.junit.runner.JUnitCore
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 13 more

incorrect code lens

The code lenses for testing are not removed when the @Test annotation is removed from a test method.

image

Not working well in spring boot junit test

It seems the spring boot context can't read configuration properly when running case, the test case src structure is followed maven default standard. The case can be executed on Eclipse IDE so it can't be case issue. Not sure if there is someway to config resource in test running to solve the issue. Thanks for your attention.

Support for TestNG

TestNG may be a bit of a niche, but it's a good and cozy niche to be in. Are there any plans to support it as well?

Add options to optionally show test report in side view

Now test reports are always shown in side view. This is disturbing for users with smaller screens (laptop).

Please add an option to show test report in side view (defauts to true). So when users set it to false, then the reports are shown in the current column.

Doesn't work with Parameterized

package com.example.demo;

import java.util.Arrays;
import java.util.List;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

@RunWith(Parameterized.class)
public class ParamTests {

    @Parameters
	public static List<Object[]> parameters() {
        return Arrays.asList(new Object[] {"foo"}, new Object[] {"bar"});
    }

   public ParamTests(String value) {}

   @Test
   public void test() {
   }
}

Click on "Run Test" on the class level and it runs them, but no status is available. And actually, if the test fails, it's just the same (status is a big "?").

Click on "Run Test" (on the @Test). Result:

@@<{"name":"testReporterAttached"}>
@@<{"name":"rootName", "attributes":{"name":"Default Suite"}}>
@@<{"name":"suiteTreeStarted", "attributes":{"name":"org.junit.runner.manipulation.Filter", "location":"java:test://org.junit.runner.manipulation.Filter"}}>
@@<{"name":"suiteTreeNode", "attributes":{"name":"initializationError", "location":"java:test://org.junit.runner.manipulation.Filter.initializationError"}}>
@@<{"name":"suiteTreeEnded", "attributes":{"name":"org.junit.runner.manipulation.Filter", "location":"java:test://org.junit.runner.manipulation.Filter"}}>
@@<{"name":"testSuiteStarted", "attributes":{"name":"org.junit.runner.manipulation.Filter", "location":"java:test://org.junit.runner.manipulation.Filter"}}>
@@<{"name":"testStarted", "attributes":{"name":"initializationError", "location":"java:test://org.junit.runner.manipulation.Filter.initializationError"}}>
@@<{"name":"testFailed", "attributes":{"name":"initializationError", "message":"No tests found matching Method test(com.example.demo.ParamTests) from org.junit.internal.requests.ClassRequest@5b80350b", "details":"java.lang.Exception: No tests found matching Method test(com.example.demo.ParamTests) from org.junit.internal.requests.ClassRequest@5b80350b\n\tat org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40)\n\tat com.microsoft.java.test.runner.TestRunnerUtil.getRequestForOneMethod(TestRunnerUtil.java:50)\n\tat com.microsoft.java.test.runner.TestRunnerUtil.createTestReferences(TestRunnerUtil.java:38)\n\tat com.microsoft.java.test.runner.CustomizedJUnitCoreRunner.run(CustomizedJUnitCoreRunner.java:26)\n\tat com.microsoft.java.test.runner.JUnitLauncher.main(JUnitLauncher.java:21)\n", "duration":"1"}}>
@@<{"name":"testFinished", "attributes":{"name":"initializationError", "duration":"2"}}>
@@<{"name":"testSuiteFinished", "attributes":{"name":"org.junit.runner.manipulation.Filter"}}>
Total tests run: 1, Failures: 1, Skips: 0

[Mac] Couldn't find Java home...

After install Java Test Runner extension, vscode pop up a message box saying Couldn't find Java home....
But vscode-java-debug and jdt.ls extensions can work successfully.

0.2.0 Plan

  • Test Explorer #45
  • Show test statistics in status bar #46
  • Should not prompt save when closing test log #23
  • Clear test result when test code changes #42
  • Provide switch to optionally show output window #41
  • Use the right color scheme to show test case status vividly #47
  • Fix #34
  • Make test report more user friendly

Test Plan - #49

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.