Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Adopt to the new VS Code tests API #1257

Merged
merged 22 commits into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b25e099
initialize the repo (#1237)
jdneo Jul 27, 2021
93f01d7
Add command to list Java projects (#1238)
jdneo Jul 28, 2021
eda2f32
Add load project logic at client side (#1239)
jdneo Jul 28, 2021
eb1c3c5
List packages and classes at server side (#1240)
jdneo Jul 28, 2021
53515e0
Support list package at client side (#1241)
jdneo Jul 28, 2021
155611a
List children of a class (#1242)
jdneo Jul 28, 2021
21cf7f3
List test classes & methods in a file (#1243)
jdneo Jul 29, 2021
f453aa8
Watch the workspace changes at client (#1244)
jdneo Jul 29, 2021
2c041d6
Update test items when document changes (#1246)
jdneo Aug 2, 2021
0a2df26
Resolve launch parameters for test runner (#1247)
jdneo Aug 2, 2021
090802c
Run test from controller (#1248)
jdneo Aug 2, 2021
175934d
Support find test location from full name (#1249)
jdneo Aug 2, 2021
3eebaee
Adopt new testing apis for all the runners (#1250)
jdneo Aug 2, 2021
2ca4ab9
Can open stacktrace (#1251)
jdneo Aug 2, 2021
732da97
Add commands to the test explorer (#1252)
jdneo Aug 2, 2021
257d92c
Add commands for the Java project explorer (#1253)
jdneo Aug 2, 2021
ff71460
Update the document (#1254)
jdneo Aug 3, 2021
f3c0afd
Add changelog (#1255)
jdneo Aug 3, 2021
d23b06c
Can navigate to source from TestNG's stacktrace (#1256)
jdneo Aug 3, 2021
a9414f3
Disable the test since we now does not have cases
jdneo Aug 3, 2021
d14e4c8
Merge branch 'cs/1.0.0-feature' of https://github.com/microsoft/vscod…
jdneo Aug 3, 2021
5d81923
Correct the branch name
jdneo Aug 3, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ jobs:
- name: Build OSGi bundle
run: npm run build-plugin

- name: Test extension
run: DISPLAY=:99 npm test
# - name: Test extension
# run: DISPLAY=:99 npm test

- name: Print language server Log if job failed
if: ${{ failure() }}
Expand Down Expand Up @@ -107,8 +107,8 @@ jobs:
- name: Build OSGi bundle
run: npm run build-plugin

- name: Test extension
run: npm test
# - name: Test extension
# run: npm test

- name: Print language server Log if job failed
if: ${{ failure() }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ resources/templates/css/**
resources/templates/js/**
resources/templates/fonts/**
dist
**/vscode.d.ts
**/vscode.proposed.d.ts
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to the "vscode-java-test" extension will be documented in th
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## 0.31.0
### Changed
- Adopted new [VS Code testing API](https://github.com/microsoft/vscode/issues/107467). For more details, please refer to the [README page](https://github.com/microsoft/vscode-java-test/blob/main/README.md).

## 0.30.1
### Fixed
- [Bugs fixed](https://github.com/microsoft/vscode-java-test/issues?q=is%3Aissue+is%3Aclosed+label%3Abug+milestone%3A0.30.1)
Expand Down
82 changes: 37 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,101 +36,93 @@ The [Java Test Runner](https://marketplace.visualstudio.com/items?itemName=vscja
- Customize test configurations
- View test report
- View tests in Test Explorer
- Show test logs


## Requirements

- JDK (version 11 or later)
- VS Code (version 1.44.0 or later)
- VS Code (version 1.59.0 or later)
- [Language Support for Java by Red Hat](https://marketplace.visualstudio.com/items?itemName=redhat.java)
- [Debugger for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug)

## Quickstart

![Run/debug JUnit test](demo/demo.gif)

### Getting Started for JUnit 5

Please refer to [Getting Started](https://junit.org/junit5/docs/current/user-guide/#overview-getting-started) from the JUnit 5's official document for getting started guide.

> Note: You can use [junit-platform-console-standalone.jar](https://search.maven.org/search?q=g:org.junit.platform%20AND%20a:junit-platform-console-standalone) in projects that manually manage their dependencies similar to the [plain-old JAR known from JUnit 4](https://github.com/junit-team/junit4/wiki/Download-and-Install#plain-old-jar).

### Getting Started for JUnit 4
Please refer to [Download and Install](https://github.com/junit-team/junit4/wiki/Download-and-Install) from the JUnit 4's official document for the getting started guide.

### Getting Started for TestNG

Please refer to [TestNG Docs](https://testng.org/doc/) from the TestNG's official document for getting started guide.

## Features

### Run/Debug Test Cases
<p align="center">
<img src="https://raw.githubusercontent.com/Microsoft/vscode-java-test/master/demo/run_codelens.png" style="border-radius: 15px" alt="Run Code Lens"/>
<img src="https://raw.githubusercontent.com/Microsoft/vscode-java-test/master/demo/editor-decoration.png" alt="Run/Debug Test Cases"/>
</p>

- The extension will generate `Run Test` and `Debug Test` shortcuts (also known as Code Lens) above the class and method definition. Simply click on them will start running or debugging the target test cases.

> Note: If you cannot see the Code Lens in your editor, please refer to this [issue comment](https://github.com/Microsoft/vscode-java-test/issues/470#issuecomment-444681714) as a workaround.
- 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

<p align="center">
<img src="https://raw.githubusercontent.com/Microsoft/vscode-java-test/master/demo/run_explorer.png" style="border-radius: 15px" alt="Run Explorer"/>
<img src="https://raw.githubusercontent.com/Microsoft/vscode-java-test/master/demo/test_explorer.png" alt="Test Explorer"/>
</p>

- The Test Explorer is the place to show all the test cases in your project. You can also run/debug your test cases from here.
- Click the node in the Test Explorer will navigate to the location of the source code.

> Note: If the Test Explorer is empty, please refer to this [issue comment](https://github.com/Microsoft/vscode-java-test/issues/470#issuecomment-444681714) as a workaround.
- 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
<p align="center">
<img src="https://raw.githubusercontent.com/Microsoft/vscode-java-test/master/demo/configuration.png" style="border-radius: 15px" alt="Customize Test Configurations"/>
<img src="https://raw.githubusercontent.com/Microsoft/vscode-java-test/master/demo/configuration.png" alt="Customize Test Configurations"/>
</p>

- Sometimes you may want to customize the configuration for running the test cases. To achieve this, you can add it into your workspace settings under the section: `java.test.config`.
- 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](https://github.com/Microsoft/vscode-java-test/wiki/Run-with-Configuration).

---

### View Test Report
### View Test Result

<p align="center">
<img src="https://raw.githubusercontent.com/Microsoft/vscode-java-test/master/demo/status_bar.png" style="border-radius: 15px" alt="Status Bar"/>
<img src="https://raw.githubusercontent.com/Microsoft/vscode-java-test/master/demo/test_report.png" alt="View Test Result"/>
</p>

- After running/debugging the test cases, the status bar will show the final results. Simply click on it to show the Test Report.
- You can also click the ✔️ or ❌ mark in Code Lens to open the Test Report.
- 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

<p align="center">
<img src="https://raw.githubusercontent.com/Microsoft/vscode-java-test/master/demo/report_navigate.png" style="border-radius: 15px" alt="Status Bar"/>
<img src="https://raw.githubusercontent.com/Microsoft/vscode-java-test/master/demo/command_palette.png" alt="VS Code Embedded Commands for Testing"/>
</p>

- You can navigate to the source location of the target test case by clicking the navigate button.

> Note: You can use `java.test.report.showAfterExecution` to configure whether to automatically show the test report after execution. By default, it will be shown when there are failed tests.

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.report.position` | Specify where to show the test report. Supported values are: `sideView`, `currentView`. | `sideView` |
| `java.test.report.showAfterExecution` | Specify if the test report will automatically be shown after execution. Supported values are: `always`, `onFailure`, `never`. | `onFailure` |
| `java.test.editor.enableShortcuts` | Specify whether to show the Code Lenses in editor or not. | `true` |
| `java.test.log.level` | Specify the level of the test logs. Supported values are: `error`, `info`, `verbose`. | `info` |
| `java.test.config` | Specify the configuration for the test cases to run with. [More details](https://aka.ms/java-test-config). | `{}` |
| `java.test.defaultConfig` | Specify the name of the default test configuration. | `""` |

### VS Code Embedded Settings for Testing

<p align="center">
<img src="https://raw.githubusercontent.com/Microsoft/vscode-java-test/master/demo/settings.png" alt="VS Code Embedded Settings for Testing"/>
</p>

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](https://junit.org/junit5/docs/current/user-guide/#overview-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](https://search.maven.org/search?q=g:org.junit.platform%20AND%20a:junit-platform-console-standalone) is on your project classpath.

### JUnit 4
Please refer to [Download and Install](https://github.com/junit-team/junit4/wiki/Download-and-Install) from the JUnit 4's official document for the getting started documentation.

### TestNG
Please refer to [TestNG Docs](https://testng.org/doc/) 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](https://github.com/microsoft/vscode-java-test/wiki/FAQ) to check if there is an answer to your problem.
If you meet any problem when using the extension, please refer to the [FAQ](https://github.com/microsoft/vscode-java-test/wiki/FAQ) and our [issue list](https://github.com/microsoft/vscode-java-test/issues) to check if there is an answer to your problem.

## Contributing and Feedback

Expand Down
Binary file added demo/command_palette.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/configuration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed demo/demo.gif
Binary file not shown.
Binary file added demo/editor-decoration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed demo/report_navigate.png
Binary file not shown.
Binary file removed demo/run_codelens.png
Binary file not shown.
Binary file removed demo/run_explorer.png
Binary file not shown.
Binary file added demo/settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed demo/status_bar.png
Binary file not shown.
Binary file added demo/test_explorer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo/test_report.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 0 additions & 8 deletions extension.bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,4 @@
// Licensed under the MIT license.

export { activate, deactivate } from './src/extension';
export * from './src/codelens/TestCodeLensProvider';
export * from './src/codelens/TestCodeLensController';
export * from './src/runners/models';
export * from './src/testResultManager';
export * from './src/protocols';
export * from './src/utils/commandUtils';
export * from './src/testFileWatcher';
export * from './src/runners/runnerScheduler';
export * from './src/provider/testSourceProvider';
20 changes: 0 additions & 20 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
const gulp = require('gulp');
const cp = require('child_process');
const tslint = require('gulp-tslint');
const sass = require('gulp-sass')(require('sass'));
const path = require('path');
const fs = require('fs');
const remoteSrc = require('gulp-remote-src');

const serverDir = path.join(__dirname, 'java-extension');
const resourceDir = path.join(__dirname, 'resources');
Expand Down Expand Up @@ -54,24 +52,6 @@ gulp.task('tslint', (done) => {

gulp.task('lint', gulp.series('tslint'));

// Test report resources
gulp.task('sass', (done) => {
gulp.src(['resources/templates/scss/*.scss'])
.pipe(sass())
.pipe(gulp.dest('resources/templates/css'));
done();
});

gulp.task('download-resources', (done) => {
remoteSrc(['jquery-3.5.1.slim.min.js'], { base: 'https://code.jquery.com/' })
.pipe(gulp.dest(path.join(resourceDir, 'templates', 'js')));
remoteSrc(['bootstrap.bundle.min.js'], { base: 'https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/' })
.pipe(gulp.dest(path.join(resourceDir, 'templates', 'js')));
done();
});

gulp.task('build-resources', gulp.series('sass', 'download-resources'));

function isWin() {
return /^win/.test(process.platform);
}
Expand Down
2 changes: 1 addition & 1 deletion java-extension/build-tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.microsoft.java.test</groupId>
<artifactId>parent</artifactId>
<version>0.30.1</version>
<version>0.31.0</version>
</parent>
<groupId>com.microsoft.java.test</groupId>
<artifactId>test-runner-build-tools</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<site>
<bundle id="com.microsoft.java.test.plugin" version="0.30.1"/>
<bundle id="com.microsoft.java.test.plugin" version="0.31.0"/>
</site>
2 changes: 1 addition & 1 deletion java-extension/com.microsoft.java.test.plugin.site/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>parent</artifactId>
<groupId>com.microsoft.java.test</groupId>
<version>0.30.1</version>
<version>0.31.0</version>
</parent>
<artifactId>com.microsoft.java.test.plugin.site</artifactId>
<packaging>eclipse-repository</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: com.microsoft.java.test.plugin
Bundle-SymbolicName: com.microsoft.java.test.plugin;singleton:=true
Bundle-Version: 0.30.1
Bundle-Version: 0.31.0
Bundle-Activator: com.microsoft.java.test.plugin.util.JUnitPlugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: org.eclipse.jdt.core,
Expand Down
9 changes: 5 additions & 4 deletions java-extension/com.microsoft.java.test.plugin/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
<extension point="org.eclipse.jdt.ls.core.delegateCommandHandler">
<delegateCommandHandler class="com.microsoft.java.test.plugin.handler.TestDelegateCommandHandler">
<command id="vscode.java.test.get.testpath" />
<command id="vscode.java.test.search.items" />
<command id="vscode.java.test.search.items.all" />
<command id="vscode.java.test.search.codelens" />
<command id="vscode.java.test.search.location" />
<command id="vscode.java.test.junit.argument" />
<command id="vscode.java.test.generateTests" />
<command id="vscode.java.test.findJavaProjects" />
<command id="vscode.java.test.findTestPackagesAndTypes" />
<command id="vscode.java.test.findDirectTestChildrenForClass" />
<command id="vscode.java.test.findTestTypesAndMethods" />
<command id="vscode.java.test.resolvePath" />
</delegateCommandHandler>
</extension>
</plugin>
2 changes: 1 addition & 1 deletion java-extension/com.microsoft.java.test.plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.microsoft.java.test</groupId>
<artifactId>parent</artifactId>
<version>0.30.1</version>
<version>0.31.0</version>
</parent>
<artifactId>com.microsoft.java.test.plugin</artifactId>
<packaging>eclipse-plugin</packaging>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2019 Microsoft Corporation and others.
* Copyright (c) 2017-2021 Microsoft Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -26,12 +26,14 @@
public class TestDelegateCommandHandler implements IDelegateCommandHandler {

private static final String GET_TEST_SOURCE_PATH = "vscode.java.test.get.testpath";
private static final String SEARCH_TEST_ITEMS = "vscode.java.test.search.items";
private static final String SEARCH_TEST_ALL_ITEMS = "vscode.java.test.search.items.all";
private static final String SEARCH_TEST_CODE_LENS = "vscode.java.test.search.codelens";
private static final String SEARCH_TEST_LOCATION = "vscode.java.test.search.location";
private static final String RESOLVE_JUNIT_ARGUMENT = "vscode.java.test.junit.argument";
private static final String GENERATE_TESTS = "vscode.java.test.generateTests";
private static final String FIND_JAVA_PROJECT = "vscode.java.test.findJavaProjects";
private static final String FIND_PACKAGES_AND_TYPES = "vscode.java.test.findTestPackagesAndTypes";
private static final String FIND_DIRECT_CHILDREN_FOR_CLASS = "vscode.java.test.findDirectTestChildrenForClass";
private static final String FIND_TYPES_AND_METHODS = "vscode.java.test.findTestTypesAndMethods";
private static final String RESOLVE_PATH = "vscode.java.test.resolvePath";
private static final String FIND_TEST_LOCATION = "vscode.java.test.findTestLocation";

@Override
public Object executeCommand(String commandId, List<Object> arguments, IProgressMonitor monitor) throws Exception {
Expand All @@ -42,18 +44,22 @@ public Object executeCommand(String commandId, List<Object> arguments, IProgress
switch (commandId) {
case GET_TEST_SOURCE_PATH:
return ProjectTestUtils.listTestSourcePaths(arguments, monitor);
case SEARCH_TEST_ITEMS:
return TestSearchUtils.searchTestItems(arguments, monitor);
case SEARCH_TEST_ALL_ITEMS:
return TestSearchUtils.searchAllTestItems(arguments, monitor);
case SEARCH_TEST_CODE_LENS:
return TestSearchUtils.searchCodeLens(arguments, monitor);
case SEARCH_TEST_LOCATION:
return TestSearchUtils.searchLocation(arguments, monitor);
case RESOLVE_JUNIT_ARGUMENT:
return JUnitLaunchUtils.resolveLaunchArgument(arguments, monitor);
case GENERATE_TESTS:
return TestGenerationUtils.generateTests(arguments, monitor);
case FIND_JAVA_PROJECT:
return TestSearchUtils.findJavaProjects(arguments, monitor);
case FIND_PACKAGES_AND_TYPES:
return TestSearchUtils.findTestPackagesAndTypes(arguments, monitor);
case FIND_DIRECT_CHILDREN_FOR_CLASS:
return TestSearchUtils.findDirectTestChildrenForClass(arguments, monitor);
case FIND_TYPES_AND_METHODS:
return TestSearchUtils.findTestTypesAndMethods(arguments, monitor);
case RESOLVE_PATH:
return TestSearchUtils.resolvePath(arguments, monitor);
case FIND_TEST_LOCATION:
return TestSearchUtils.findTestLocation(arguments, monitor);
default:
throw new UnsupportedOperationException(
String.format("Java test plugin doesn't support the command '%s'.", commandId));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 Microsoft Corporation and others.
* Copyright (c) 2019-2021 Microsoft Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -11,11 +11,10 @@

package com.microsoft.java.test.plugin.launchers;

import com.microsoft.java.test.plugin.util.JUnitPlugin;
import org.apache.commons.lang3.text.StrSubstitutor;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.internal.core.LaunchConfiguration;
import org.eclipse.debug.internal.core.LaunchConfigurationInfo;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
Expand Down Expand Up @@ -84,26 +83,21 @@ public JUnitLaunchConfigurationInfo(TestInfo testInfo) throws CoreException {
final Element root = parser.parse(source).getDocumentElement();
initializeFromXML(root);
} catch (ParserConfigurationException | SAXException | IOException | CoreException e) {
// do nothing
throw new CoreException(new Status(IStatus.ERROR, "com.microsoft.java.test.plugin.launchers",
"Failed to load JUnit launch configuration", e));
JUnitPlugin.logException("Failed to load JUnit launch configuration.", e);
}
}
}

class TestInfo {
public String mainType = "";
public String testContainer = "";
public String testKind = "";
public String testName = "";
public String[] testNames;
public IProject project;

public Map<String, String> toValueMap() {
final Map<String, String> valueMap = new HashMap<>();
valueMap.put("testContainer", testContainer);
valueMap.put("testName", testName);
valueMap.put("testKind", testKind);
valueMap.put("mainType", mainType);
return valueMap;
}
}
Loading