test: Refactor the test code (#1170)
This commit is contained in:
Родитель
406e9f876f
Коммит
39602e7e85
|
@ -107,9 +107,8 @@ jobs:
|
|||
- name: Build OSGi bundle
|
||||
run: npm run build-plugin
|
||||
|
||||
# TODO: Enable the darwin build after figure out how to stop Gradle Daemon
|
||||
# - name: Test extension
|
||||
# run: npm test
|
||||
- name: Test extension
|
||||
run: npm test
|
||||
|
||||
- name: Print language server Log if job failed
|
||||
if: ${{ failure() }}
|
||||
|
|
|
@ -25,11 +25,11 @@
|
|||
"projectName": "com.microsoft.java.test.plugin",
|
||||
},
|
||||
{
|
||||
"name": "Launch Tests (webpack) - Maven JUnit4 Code Lens",
|
||||
"name": "Launch Tests (webpack) - Maven JUnit",
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"runtimeExecutable": "${execPath}",
|
||||
"args": ["${workspaceFolder}/test/test-projects/junit4", "--extensionDevelopmentPath=${workspaceFolder}", "--extensionTestsPath=${workspaceFolder}/dist/test/maven-junit4-suite" ],
|
||||
"args": ["${workspaceFolder}/test/test-projects/junit", "--extensionDevelopmentPath=${workspaceFolder}", "--extensionTestsPath=${workspaceFolder}/dist/test/maven-junit-suite" ],
|
||||
"sourceMaps": true,
|
||||
"outFiles": [ "${workspaceFolder}/dist/**/*.js" ],
|
||||
"preLaunchTask": "npm: compile"
|
||||
|
@ -43,16 +43,6 @@
|
|||
"sourceMaps": true,
|
||||
"outFiles": [ "${workspaceFolder}/dist/**/*.js" ],
|
||||
"preLaunchTask": "npm: compile"
|
||||
},
|
||||
{
|
||||
"name": "Launch Tests (webpack) - Gradle JUnit5",
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"runtimeExecutable": "${execPath}",
|
||||
"args": ["${workspaceFolder}/test/test-projects/junit5", "--extensionDevelopmentPath=${workspaceFolder}", "--extensionTestsPath=${workspaceFolder}/dist/test/gradle-junit5-suite" ],
|
||||
"sourceMaps": true,
|
||||
"outFiles": [ "${workspaceFolder}/dist/**/*.js" ],
|
||||
"preLaunchTask": "npm: compile"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -94,9 +94,9 @@
|
|||
}
|
||||
},
|
||||
"@sinonjs/commons": {
|
||||
"version": "1.8.2",
|
||||
"resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.2.tgz",
|
||||
"integrity": "sha512-sruwd86RJHdsVf/AtBoijDmUqJp3B6hF/DGC23C+JaegnDHaZyewCjoVGTdg3J0uz3Zs7NnIT05OBOmML72lQw==",
|
||||
"version": "1.8.3",
|
||||
"resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.3.tgz",
|
||||
"integrity": "sha512-xkNcLAn/wZaX14RPlwizcKicDk9G3F8m2nU3L7Ukm5zBgTwiT0wsoFAHx9Jq56fJA1z/7uKGtCRu16sOUCLIHQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"type-detect": "4.0.8"
|
||||
|
@ -3901,9 +3901,9 @@
|
|||
}
|
||||
},
|
||||
"hosted-git-info": {
|
||||
"version": "2.8.8",
|
||||
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.8.tgz",
|
||||
"integrity": "sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg==",
|
||||
"version": "2.8.9",
|
||||
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz",
|
||||
"integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==",
|
||||
"dev": true
|
||||
},
|
||||
"http-proxy-agent": {
|
||||
|
@ -5466,9 +5466,9 @@
|
|||
}
|
||||
},
|
||||
"y18n": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.2.tgz",
|
||||
"integrity": "sha512-DnBDwcL54b5xWMM/7RfFg4xs5amYxq2ot49aUfLjQSAracXkGvlZq0txzqr3Pa6Q0ayuCxBcwTzrPUScKY0O8w==",
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz",
|
||||
"integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==",
|
||||
"dev": true
|
||||
},
|
||||
"yargs": {
|
||||
|
@ -6972,9 +6972,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"repeat-element": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/repeat-element/-/repeat-element-1.1.3.tgz",
|
||||
"integrity": "sha512-ahGq0ZnV5m5XtZLMb+vP76kcAM5nkLqk0lpqAuojSKGgQtn4eRi4ZZGm2olo2zKFH+sMsWaqOCW1dqAnOru72g==",
|
||||
"version": "1.1.4",
|
||||
"resolved": "https://registry.npmjs.org/repeat-element/-/repeat-element-1.1.4.tgz",
|
||||
"integrity": "sha512-LFiNfRcSu7KK3evMyYOuCzv3L10TW7yC1G2/+StMjK8Y6Vqd2MG7r/Qjw4ghtuCOjFvlnms/iMmLqpvW/ES/WQ==",
|
||||
"dev": true
|
||||
},
|
||||
"repeat-string": {
|
||||
|
@ -7301,9 +7301,9 @@
|
|||
}
|
||||
},
|
||||
"y18n": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.2.tgz",
|
||||
"integrity": "sha512-DnBDwcL54b5xWMM/7RfFg4xs5amYxq2ot49aUfLjQSAracXkGvlZq0txzqr3Pa6Q0ayuCxBcwTzrPUScKY0O8w==",
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz",
|
||||
"integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==",
|
||||
"dev": true
|
||||
},
|
||||
"yargs": {
|
||||
|
@ -8254,18 +8254,18 @@
|
|||
}
|
||||
},
|
||||
"ssri": {
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/ssri/-/ssri-6.0.1.tgz",
|
||||
"integrity": "sha512-3Wge10hNcT1Kur4PDFwEieXSCMCJs/7WvSACcrMYrNp+b8kDL1/0wJch5Ni2WrtwEa2IO8OsVfeKIciKCDx/QA==",
|
||||
"version": "6.0.2",
|
||||
"resolved": "https://registry.npmjs.org/ssri/-/ssri-6.0.2.tgz",
|
||||
"integrity": "sha512-cepbSq/neFK7xB6A50KHN0xHDotYzq58wWCa5LeWqnPrHG8GzfEjO/4O8kpmcGW+oaxkvhEJCWgbgNk4/ZV93Q==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"figgy-pudding": "^3.5.1"
|
||||
}
|
||||
},
|
||||
"y18n": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.2.tgz",
|
||||
"integrity": "sha512-DnBDwcL54b5xWMM/7RfFg4xs5amYxq2ot49aUfLjQSAracXkGvlZq0txzqr3Pa6Q0ayuCxBcwTzrPUScKY0O8w==",
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz",
|
||||
"integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==",
|
||||
"dev": true
|
||||
},
|
||||
"yallist": {
|
||||
|
@ -9669,9 +9669,9 @@
|
|||
}
|
||||
},
|
||||
"y18n": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.2.tgz",
|
||||
"integrity": "sha512-DnBDwcL54b5xWMM/7RfFg4xs5amYxq2ot49aUfLjQSAracXkGvlZq0txzqr3Pa6Q0ayuCxBcwTzrPUScKY0O8w==",
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz",
|
||||
"integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==",
|
||||
"dev": true
|
||||
},
|
||||
"yargs": {
|
||||
|
@ -10024,9 +10024,9 @@
|
|||
}
|
||||
},
|
||||
"y18n": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.2.tgz",
|
||||
"integrity": "sha512-DnBDwcL54b5xWMM/7RfFg4xs5amYxq2ot49aUfLjQSAracXkGvlZq0txzqr3Pa6Q0ayuCxBcwTzrPUScKY0O8w==",
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz",
|
||||
"integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==",
|
||||
"dev": true
|
||||
},
|
||||
"yargs": {
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { commands, extensions } from 'vscode';
|
||||
import { testResultManager } from '../../extension.bundle';
|
||||
|
||||
suite('Test Explorer Tests', function() {
|
||||
|
||||
suiteSetup(async function() {
|
||||
await extensions.getExtension('vscjava.vscode-java-test')!.activate();
|
||||
testResultManager.dispose();
|
||||
});
|
||||
|
||||
test("Can run all the tests", async function() {
|
||||
await commands.executeCommand('java.test.explorer.runAll');
|
||||
|
||||
assert.ok(testResultManager.getResultById('junit5@junit5.ParameterizedAnnotationTest#canRunWithComment'));
|
||||
assert.ok(testResultManager.getResultById('junit5@junit5.ParameterizedAnnotationTest#equal'));
|
||||
assert.ok(testResultManager.getResultById('junit5@junit5.PropertyTest#absoluteValueOfIntegerAlwaysPositive'));
|
||||
assert.ok(testResultManager.getResultById('junit5@junit5.NestedTest$NestedClassA#test'));
|
||||
assert.ok(testResultManager.getResultById('junit5@junit5.NestedTest$NestedClassB#test'));
|
||||
assert.ok(testResultManager.getResultById('junit5@junit5.NestedTest$NestedClassB$ADeeperClass#test'));
|
||||
});
|
||||
|
||||
teardown(async function() {
|
||||
testResultManager.dispose();
|
||||
});
|
||||
});
|
|
@ -1,33 +0,0 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import * as glob from 'glob';
|
||||
import * as Mocha from 'mocha';
|
||||
import * as path from 'path';
|
||||
|
||||
export function run(testsRoot: string, cb: (error: any, failures?: number) => void): void {
|
||||
// Create the mocha test
|
||||
const mocha = new Mocha({
|
||||
ui: 'tdd',
|
||||
timeout: 60 * 1000, /*ms*/
|
||||
});
|
||||
mocha.useColors(true);
|
||||
|
||||
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
|
||||
if (err) {
|
||||
return cb(err);
|
||||
}
|
||||
|
||||
// Add files to the test suite
|
||||
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
|
||||
|
||||
try {
|
||||
// Run the mocha test
|
||||
mocha.run(failures => {
|
||||
cb(null, failures);
|
||||
});
|
||||
} catch (err) {
|
||||
cb(err);
|
||||
}
|
||||
});
|
||||
}
|
|
@ -4,13 +4,14 @@
|
|||
import * as assert from 'assert';
|
||||
import { CodeLens, Command, commands, TextDocument, window, workspace } from 'vscode';
|
||||
import { ITestResult, TestCodeLensProvider, testResultManager, ITestItem } from '../../extension.bundle';
|
||||
import { getJavaVersion, Token, Uris } from '../shared';
|
||||
import { getJavaVersion, setupTestEnv, Token, Uris } from '../shared';
|
||||
|
||||
suite('Modular Porject Tests', function() {
|
||||
suite('Modular Project Tests', function() {
|
||||
|
||||
let javaVersion: number = -1;
|
||||
|
||||
suiteSetup(async function() {
|
||||
setupTestEnv();
|
||||
javaVersion = await getJavaVersion();
|
||||
});
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
import * as cp from 'child_process';
|
||||
import * as path from 'path';
|
||||
import { downloadAndUnzipVSCode, resolveCliPathFromVSCodeExecutablePath, runTests } from 'vscode-test';
|
||||
import * as util from 'util';
|
||||
|
||||
async function main(): Promise<void> {
|
||||
try {
|
||||
|
@ -24,15 +25,16 @@ async function main(): Promise<void> {
|
|||
stdio: 'inherit',
|
||||
});
|
||||
|
||||
// Run Maven JUnit 4 Code Lens tests
|
||||
// Run Maven JUnit tests
|
||||
await runTests({
|
||||
vscodeExecutablePath,
|
||||
extensionDevelopmentPath,
|
||||
extensionTestsPath: path.resolve(__dirname, './maven-junit4-suite'),
|
||||
extensionTestsPath: path.resolve(__dirname, './maven-junit-suite'),
|
||||
launchArgs: [
|
||||
path.join(__dirname, '..', '..', 'test', 'test-projects', 'junit4'),
|
||||
path.join(__dirname, '..', '..', 'test', 'test-projects', 'junit'),
|
||||
],
|
||||
});
|
||||
await killJavaProcess();
|
||||
|
||||
// Run Gradle modular project tests
|
||||
await runTests({
|
||||
|
@ -43,21 +45,26 @@ async function main(): Promise<void> {
|
|||
path.join(__dirname, '..', '..', 'test', 'test-projects', 'modular-gradle'),
|
||||
],
|
||||
});
|
||||
|
||||
// Run Gradle JUnit 5 project tests
|
||||
await runTests({
|
||||
vscodeExecutablePath,
|
||||
extensionDevelopmentPath,
|
||||
extensionTestsPath: path.resolve(__dirname, './gradle-junit5-suite'),
|
||||
launchArgs: [
|
||||
path.join(__dirname, '..', '..', 'test', 'test-projects', 'junit5'),
|
||||
],
|
||||
});
|
||||
|
||||
await killJavaProcess();
|
||||
} catch (err) {
|
||||
console.error('Failed to run tests');
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function killJavaProcess(): Promise<void> {
|
||||
const execAsync = util.promisify(cp.exec);
|
||||
try {
|
||||
if (process.platform === "win32") {
|
||||
await execAsync(`wmic process where "name like '%java%'" delete`);
|
||||
} else {
|
||||
await execAsync("kill -9 $(jps | awk '{print $1}')");
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
|
||||
import * as assert from 'assert';
|
||||
import * as path from "path";
|
||||
import { commands, TextDocument, window, workspace, extensions, Uri } from 'vscode';
|
||||
import { commands, TextDocument, window, workspace, Uri } from 'vscode';
|
||||
import { searchTestLocation, ILocation } from '../../extension.bundle';
|
||||
import { Uris } from '../shared';
|
||||
import { setupTestEnv, Uris } from '../shared';
|
||||
|
||||
suite('Command Utils Tests', function() {
|
||||
|
||||
suiteSetup(async function() {
|
||||
await extensions.getExtension('vscjava.vscode-java-test')!.activate();
|
||||
setupTestEnv()
|
||||
});
|
||||
|
||||
test("Can search location for <TestError> items", async function() {
|
|
@ -0,0 +1,30 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { commands } from 'vscode';
|
||||
import { testResultManager } from '../../extension.bundle';
|
||||
import { setupTestEnv } from '../shared';
|
||||
|
||||
suite('Test Explorer Tests', function() {
|
||||
|
||||
suiteSetup(async function() {
|
||||
setupTestEnv();
|
||||
testResultManager.dispose();
|
||||
});
|
||||
|
||||
test("Can run all the tests", async function() {
|
||||
await commands.executeCommand('java.test.explorer.runAll');
|
||||
|
||||
assert.ok(testResultManager.getResultById('junit@junit5.ParameterizedAnnotationTest#canRunWithComment'));
|
||||
assert.ok(testResultManager.getResultById('junit@junit5.ParameterizedAnnotationTest#equal'));
|
||||
assert.ok(testResultManager.getResultById('junit@junit5.PropertyTest#absoluteValueOfIntegerAlwaysPositive'));
|
||||
assert.ok(testResultManager.getResultById('junit@junit5.NestedTest$NestedClassA#test'));
|
||||
assert.ok(testResultManager.getResultById('junit@junit5.NestedTest$NestedClassB#test'));
|
||||
assert.ok(testResultManager.getResultById('junit@junit5.NestedTest$NestedClassB$ADeeperClass#test'));
|
||||
});
|
||||
|
||||
teardown(async function() {
|
||||
testResultManager.dispose();
|
||||
});
|
||||
});
|
|
@ -2,14 +2,14 @@
|
|||
// Licensed under the MIT license.
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { CodeLens, Command, commands, TextDocument, window, workspace, extensions } from 'vscode';
|
||||
import { CodeLens, Command, commands, TextDocument, window, workspace } from 'vscode';
|
||||
import { IExecutionCache, ITestResult, runnerScheduler, TestCodeLensProvider, testResultManager, TestStatus, ITestItem } from '../../extension.bundle';
|
||||
import { Token, Uris } from '../shared';
|
||||
import { setupTestEnv, Token, Uris } from '../shared';
|
||||
|
||||
suite('Code Lens Tests', function() {
|
||||
|
||||
suiteSetup(async function() {
|
||||
await extensions.getExtension('vscjava.vscode-java-test')!.activate();
|
||||
setupTestEnv()
|
||||
});
|
||||
|
||||
test("Code Lens should work for JUnit 4's @Test annotation", async function() {
|
|
@ -3,18 +3,18 @@
|
|||
|
||||
import * as assert from 'assert';
|
||||
import * as fse from 'fs-extra';
|
||||
import { CodeLens, Command, commands, TextDocument, window, workspace, extensions } from 'vscode';
|
||||
import { CodeLens, Command, commands, Range, TextDocument, window, workspace, WorkspaceEdit } from 'vscode';
|
||||
import { TestCodeLensProvider, testResultManager, ITestItem, ITestResult, TestStatus } from '../../extension.bundle';
|
||||
import { Token, Uris } from '../shared';
|
||||
import { setupTestEnv, sleep, Token, Uris } from '../shared';
|
||||
|
||||
suite('Code Lens Tests', function() {
|
||||
|
||||
suiteSetup(async function() {
|
||||
await extensions.getExtension('vscjava.vscode-java-test')!.activate();
|
||||
setupTestEnv();
|
||||
});
|
||||
|
||||
test("Can run test method if it has comments above", async function() {
|
||||
const document: TextDocument = await workspace.openTextDocument(Uris.GRADLE_JUNIT5_PARAMETERIZED_TEST);
|
||||
const document: TextDocument = await workspace.openTextDocument(Uris.JUNIT5_PARAMETERIZED_TEST);
|
||||
await window.showTextDocument(document);
|
||||
|
||||
const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider();
|
||||
|
@ -38,7 +38,7 @@ suite('Code Lens Tests', function() {
|
|||
});
|
||||
|
||||
test("Can get correct result", async function() {
|
||||
const document: TextDocument = await workspace.openTextDocument(Uris.GRADLE_JUNIT5_PARAMETERIZED_TEST);
|
||||
const document: TextDocument = await workspace.openTextDocument(Uris.JUNIT5_PARAMETERIZED_TEST);
|
||||
await window.showTextDocument(document);
|
||||
|
||||
const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider();
|
||||
|
@ -58,7 +58,7 @@ suite('Code Lens Tests', function() {
|
|||
});
|
||||
|
||||
test("Can run test with generic typed parameter", async function() {
|
||||
const document: TextDocument = await workspace.openTextDocument(Uris.GRADLE_JUNIT5_PARAMETERIZED_TEST);
|
||||
const document: TextDocument = await workspace.openTextDocument(Uris.JUNIT5_PARAMETERIZED_TEST);
|
||||
await window.showTextDocument(document);
|
||||
|
||||
const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider();
|
||||
|
@ -77,7 +77,7 @@ suite('Code Lens Tests', function() {
|
|||
});
|
||||
|
||||
test("Can run test method annotated with @Testable", async function() {
|
||||
const document: TextDocument = await workspace.openTextDocument(Uris.GRADLE_JUNIT5_PROPERTY_TEST);
|
||||
const document: TextDocument = await workspace.openTextDocument(Uris.JUNIT5_PROPERTY_TEST);
|
||||
await window.showTextDocument(document);
|
||||
|
||||
const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider();
|
||||
|
@ -101,7 +101,7 @@ suite('Code Lens Tests', function() {
|
|||
});
|
||||
|
||||
test("Can show Code Lens for methods annotated with meta-annotation", async function() {
|
||||
const document: TextDocument = await workspace.openTextDocument(Uris.GRADLE_JUNIT5_META_ANNOTATION_TEST);
|
||||
const document: TextDocument = await workspace.openTextDocument(Uris.JUNIT5_META_ANNOTATION_TEST);
|
||||
await window.showTextDocument(document);
|
||||
|
||||
const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider();
|
||||
|
@ -110,7 +110,7 @@ suite('Code Lens Tests', function() {
|
|||
});
|
||||
|
||||
test("Can run test method annotated with @Nested", async function() {
|
||||
const document: TextDocument = await workspace.openTextDocument(Uris.GRADLE_JUNIT5_NESTED_TEST);
|
||||
const document: TextDocument = await workspace.openTextDocument(Uris.JUNIT5_NESTED_TEST);
|
||||
await window.showTextDocument(document);
|
||||
|
||||
const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider();
|
||||
|
@ -135,35 +135,39 @@ suite('Code Lens Tests', function() {
|
|||
});
|
||||
|
||||
test("Can correctly update the test results for cucumber tests", async function() {
|
||||
const document: TextDocument = await workspace.openTextDocument(Uris.GRADLE_CUCUMBER_TEST);
|
||||
await window.showTextDocument(document);
|
||||
const fileContent: string = await fse.readFile(Uris.CUCUMBER_STEP.fsPath, 'utf-8');
|
||||
try {
|
||||
const document: TextDocument = await workspace.openTextDocument(Uris.CUCUMBER_TEST);
|
||||
await window.showTextDocument(document);
|
||||
|
||||
const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider();
|
||||
const codeLens: CodeLens[] = await codeLensProvider.provideCodeLenses(document, Token.cancellationToken);
|
||||
|
||||
const command: Command | undefined = codeLens[0].command;
|
||||
|
||||
const testItem: ITestItem[] = command!.arguments as ITestItem[];
|
||||
|
||||
await commands.executeCommand(command!.command, testItem[0]);
|
||||
const projectName: string = testItem[0].project;
|
||||
|
||||
let result: ITestResult| undefined = testResultManager.getResultById(`${projectName}@The calculator application#client wants to add 2 numbers`);
|
||||
assert.strictEqual(result!.status, TestStatus.Fail);
|
||||
|
||||
// Correct the test case
|
||||
const edit: WorkspaceEdit = new WorkspaceEdit();
|
||||
edit.replace(Uris.CUCUMBER_STEP, new Range(15, 4, 15, 31), 'assertEquals(value, 6);');
|
||||
await workspace.applyEdit(edit);
|
||||
|
||||
await commands.executeCommand('java.workspace.compile', false);
|
||||
await sleep(1000 /*ms*/);
|
||||
|
||||
const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider();
|
||||
const codeLens: CodeLens[] = await codeLensProvider.provideCodeLenses(document, Token.cancellationToken);
|
||||
|
||||
const command: Command | undefined = codeLens[0].command;
|
||||
|
||||
const testItem: ITestItem[] = command!.arguments as ITestItem[];
|
||||
|
||||
await commands.executeCommand(command!.command, testItem[0]);
|
||||
const projectName: string = testItem[0].project;
|
||||
|
||||
let result: ITestResult| undefined = testResultManager.getResultById(`${projectName}@The calculator application#client wants to add 2 numbers`);
|
||||
assert.strictEqual(result!.status, TestStatus.Fail);
|
||||
|
||||
// Correct the test case
|
||||
const fileContent: string = await fse.readFile(Uris.GRADLE_CUCUMBER_STEP.fsPath, 'utf-8');
|
||||
await fse.writeFile(Uris.GRADLE_CUCUMBER_STEP.fsPath,
|
||||
fileContent.replace('assertEquals(value + 1, 6);', 'assertEquals(value, 6);'), {encoding: 'utf-8'});
|
||||
|
||||
await commands.executeCommand('java.workspace.compile', false);
|
||||
|
||||
await commands.executeCommand('java.test.relaunch');
|
||||
result = testResultManager.getResultById(`${projectName}@The calculator application#client wants to add 2 numbers`);
|
||||
assert.strictEqual(result!.status, TestStatus.Pass);
|
||||
|
||||
// revert the file change
|
||||
await fse.writeFile(Uris.GRADLE_CUCUMBER_STEP.fsPath, fileContent, {encoding: 'utf-8'});
|
||||
await commands.executeCommand('java.test.relaunch');
|
||||
result = testResultManager.getResultById(`${projectName}@The calculator application#client wants to add 2 numbers`);
|
||||
assert.strictEqual(result!.status, TestStatus.Pass);
|
||||
} finally {
|
||||
// revert the file change
|
||||
await fse.writeFile(Uris.CUCUMBER_STEP.fsPath, fileContent, {encoding: 'utf-8'});
|
||||
}
|
||||
});
|
||||
|
||||
teardown(async function() {
|
|
@ -2,23 +2,23 @@
|
|||
// Licensed under the MIT license.
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { commands, TextDocument, window, workspace, extensions } from 'vscode';
|
||||
import { commands, TextDocument, window, workspace } from 'vscode';
|
||||
import { testResultManager, ITestResult, TestStatus } from '../../extension.bundle';
|
||||
import { Uris } from '../shared';
|
||||
import { setupTestEnv, Uris } from '../shared';
|
||||
|
||||
suite('Run from Editor Tests', function() {
|
||||
|
||||
suiteSetup(async function() {
|
||||
await extensions.getExtension('vscjava.vscode-java-test')!.activate();
|
||||
setupTestEnv();
|
||||
});
|
||||
|
||||
test("Can run from active editor", async function() {
|
||||
const document: TextDocument = await workspace.openTextDocument(Uris.GRADLE_JUNIT5_META_ANNOTATION_TEST);
|
||||
const document: TextDocument = await workspace.openTextDocument(Uris.JUNIT5_META_ANNOTATION_TEST);
|
||||
await window.showTextDocument(document);
|
||||
|
||||
await commands.executeCommand('java.test.editor.run');
|
||||
|
||||
const detail: ITestResult| undefined = testResultManager.getResultById(`junit5@junit5.MetaAnnotationTest#myFastTest`);
|
||||
const detail: ITestResult| undefined = testResultManager.getResultById(`junit@junit5.MetaAnnotationTest#myFastTest`);
|
||||
assert.strictEqual(detail!.status, TestStatus.Pass);
|
||||
});
|
||||
|
|
@ -1,26 +1,26 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import { commands, extensions, RelativePattern } from 'vscode';
|
||||
import { commands, RelativePattern } from 'vscode';
|
||||
import { testCodeLensController, testFileWatcher } from '../../extension.bundle';
|
||||
import * as assert from 'assert';
|
||||
import * as sinon from 'sinon';
|
||||
import * as path from "path";
|
||||
import { Uris } from '../shared';
|
||||
import { setupTestEnv, Uris } from '../shared';
|
||||
|
||||
suite('Test File Watcher Tests', function() {
|
||||
|
||||
const sandbox = sinon.createSandbox();
|
||||
|
||||
suiteSetup(async function() {
|
||||
await extensions.getExtension('vscjava.vscode-java-test')!.activate();
|
||||
setupTestEnv();
|
||||
});
|
||||
|
||||
test("Should correctly setup code lens provider", async function() {
|
||||
let spy: sinon.SinonSpy = sandbox.spy(testCodeLensController, 'registerCodeLensProvider');
|
||||
await testFileWatcher.registerListeners();
|
||||
const args: RelativePattern[] = spy.getCall(0).args[0];
|
||||
assert.ok(args.length === 2);
|
||||
assert.ok(args.length === 3);
|
||||
assert.ok(path.relative(args[0].base, path.join(Uris.JUNIT4_TEST_PACKAGE, '..')));
|
||||
spy.restore();
|
||||
});
|
|
@ -2,25 +2,25 @@
|
|||
// Licensed under the MIT license.
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { commands, window, extensions } from 'vscode';
|
||||
import { Uris } from '../shared';
|
||||
import { commands, window } from 'vscode';
|
||||
import { setupTestEnv, Uris } from '../shared';
|
||||
|
||||
suite('Test Report Tests', function() {
|
||||
|
||||
suiteSetup(async function() {
|
||||
await extensions.getExtension('vscjava.vscode-java-test')!.activate();
|
||||
setupTestEnv();
|
||||
await commands.executeCommand('workbench.action.closeActiveEditor');
|
||||
});
|
||||
|
||||
test("Can open test source location from uri and range", async function() {
|
||||
await commands.executeCommand(
|
||||
'java.test.report.openTestSourceLocation',
|
||||
Uris.GRADLE_JUNIT5_PARAMETERIZED_TEST.toString(),
|
||||
Uris.JUNIT5_PARAMETERIZED_TEST.toString(),
|
||||
'{"start":{"line":30,"character":16},"end":{"line":30,"character":21}}',
|
||||
undefined,
|
||||
);
|
||||
|
||||
assert.strictEqual(window.activeTextEditor?.document.uri.fsPath, Uris.GRADLE_JUNIT5_PARAMETERIZED_TEST.fsPath);
|
||||
assert.strictEqual(window.activeTextEditor?.document.uri.fsPath, Uris.JUNIT5_PARAMETERIZED_TEST.fsPath);
|
||||
assert.strictEqual(window.activeTextEditor?.selection.start.line, 30);
|
||||
});
|
||||
|
||||
|
@ -29,18 +29,18 @@ suite('Test Report Tests', function() {
|
|||
'java.test.report.openTestSourceLocation',
|
||||
undefined,
|
||||
undefined,
|
||||
'junit5@junit5.ParameterizedAnnotationTest#equal',
|
||||
'junit@junit5.ParameterizedAnnotationTest#equal',
|
||||
);
|
||||
|
||||
assert.strictEqual(window.activeTextEditor?.document.uri.fsPath, Uris.GRADLE_JUNIT5_PARAMETERIZED_TEST.fsPath);
|
||||
assert.strictEqual(window.activeTextEditor?.selection.start.line, 30);
|
||||
assert.strictEqual(window.activeTextEditor?.document.uri.fsPath, Uris.JUNIT5_PARAMETERIZED_TEST.fsPath);
|
||||
assert.strictEqual(window.activeTextEditor?.selection.start.line, 32);
|
||||
});
|
||||
|
||||
test("Can open test source location from stack trace", async function() {
|
||||
await commands.executeCommand(
|
||||
'java.test.report.openStackTrace',
|
||||
'at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:55)',
|
||||
'junit5@junit5.ParameterizedAnnotationTest#equal',
|
||||
'junit@junit5.ParameterizedAnnotationTest#equal',
|
||||
);
|
||||
|
||||
assert.ok(window.activeTextEditor?.document.uri.fsPath.endsWith('AssertionUtils.class'));
|
|
@ -2,7 +2,8 @@
|
|||
// Licensed under the MIT license.
|
||||
|
||||
import * as path from 'path';
|
||||
import { CancellationToken, Event, Uri, Extension, extensions } from 'vscode';
|
||||
import * as fse from 'fs-extra';
|
||||
import { CancellationToken, Event, Uri, Extension, extensions, workspace, commands } from 'vscode';
|
||||
|
||||
interface IDisposable {
|
||||
dispose(): void;
|
||||
|
@ -21,9 +22,9 @@ export namespace Token {
|
|||
}
|
||||
|
||||
export namespace Uris {
|
||||
// JUnit 4
|
||||
// JUnit
|
||||
const TEST_PROJECT_BASE_PATH: string = path.join(__dirname, '..', '..', 'test', 'test-projects');
|
||||
export const JUNIT4_TEST_PACKAGE: string = path.join('junit4', 'src', 'test', 'java', 'junit4');
|
||||
export const JUNIT4_TEST_PACKAGE: string = path.join('junit', 'src', 'test', 'java', 'junit4');
|
||||
export const JUNIT4_TEST: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, JUNIT4_TEST_PACKAGE, 'TestAnnotation.java'));
|
||||
export const JUNIT4_THEROY: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, JUNIT4_TEST_PACKAGE, 'TheoryAnnotation.java'));
|
||||
export const JUNIT4_RUNWITH: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, JUNIT4_TEST_PACKAGE, 'RunWithAnnotation.java'));
|
||||
|
@ -32,18 +33,42 @@ export namespace Uris {
|
|||
export const JUNIT4_PARAMETERIZED_WITH_NAME_TEST: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, JUNIT4_TEST_PACKAGE, 'ParameterizedWithNameTest.java'));
|
||||
export const JUNIT4_ASSUME_TEST: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, JUNIT4_TEST_PACKAGE, 'AssumeTest.java'));
|
||||
|
||||
// JUnit5
|
||||
const JUNIT5_TEST_PACKAGE: string = path.join('junit', 'src', 'test', 'java', 'junit5');
|
||||
export const JUNIT5_PARAMETERIZED_TEST: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, JUNIT5_TEST_PACKAGE, 'ParameterizedAnnotationTest.java'));
|
||||
export const JUNIT5_NESTED_TEST: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, JUNIT5_TEST_PACKAGE, 'NestedTest.java'));
|
||||
export const JUNIT5_META_ANNOTATION_TEST: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, JUNIT5_TEST_PACKAGE, 'MetaAnnotationTest.java'));
|
||||
export const JUNIT5_PROPERTY_TEST: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, JUNIT5_TEST_PACKAGE, 'PropertyTest.java'));
|
||||
export const CUCUMBER_TEST: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, JUNIT5_TEST_PACKAGE, 'cucumber', 'CucumberTest.java'));
|
||||
export const CUCUMBER_STEP: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, JUNIT5_TEST_PACKAGE, 'cucumber', 'CucumberSteps.java'));
|
||||
|
||||
// Gradle modular
|
||||
const MODULAR_GRADLE: string = path.join('modular-gradle', 'src', 'test', 'java', 'com', 'example', 'project');
|
||||
export const MODULAR_GRADLE_TEST: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, MODULAR_GRADLE, 'GradleModularTest.java'));
|
||||
}
|
||||
|
||||
// Gradle JUnit5
|
||||
const GRADLE_JUNIT5_TEST_PACKAGE: string = path.join('junit5', 'src', 'test', 'java', 'junit5');
|
||||
export const GRADLE_JUNIT5_PARAMETERIZED_TEST: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, GRADLE_JUNIT5_TEST_PACKAGE, 'ParameterizedAnnotationTest.java'));
|
||||
export const GRADLE_JUNIT5_NESTED_TEST: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, GRADLE_JUNIT5_TEST_PACKAGE, 'NestedTest.java'));
|
||||
export const GRADLE_JUNIT5_META_ANNOTATION_TEST: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, GRADLE_JUNIT5_TEST_PACKAGE, 'MetaAnnotationTest.java'));
|
||||
export const GRADLE_JUNIT5_PROPERTY_TEST: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, GRADLE_JUNIT5_TEST_PACKAGE, 'PropertyTest.java'));
|
||||
export const GRADLE_CUCUMBER_TEST: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, GRADLE_JUNIT5_TEST_PACKAGE, 'cucumber', 'CucumberTest.java'));
|
||||
export const GRADLE_CUCUMBER_STEP: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, GRADLE_JUNIT5_TEST_PACKAGE, 'cucumber', 'CucumberSteps.java'));
|
||||
export async function setupTestEnv() {
|
||||
await extensions.getExtension("redhat.java")!.activate();
|
||||
const javaExt = extensions.getExtension("redhat.java");
|
||||
await javaExt!.activate();
|
||||
const api = javaExt?.exports;
|
||||
while (api.serverMode !== "Standard") {
|
||||
await sleep(2 * 1000/*ms*/);
|
||||
}
|
||||
await extensions.getExtension("vscjava.vscode-java-test")!.activate();
|
||||
|
||||
const workspaceRootPath: string = workspace.workspaceFolders![0]!.uri.fsPath;
|
||||
if (await fse.pathExists(path.join(workspaceRootPath, 'pom.xml'))) {
|
||||
await commands.executeCommand('java.projectConfiguration.update', Uri.file(path.join(workspaceRootPath, 'pom.xml')));
|
||||
} else if (await fse.pathExists(path.join(workspaceRootPath, 'build.gradle'))) {
|
||||
await commands.executeCommand('java.projectConfiguration.update', Uri.file(path.join(workspaceRootPath, 'build.gradle')));
|
||||
}
|
||||
}
|
||||
|
||||
export async function sleep(ms: number) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, ms);
|
||||
});
|
||||
}
|
||||
|
||||
export async function getJavaVersion(): Promise<number> {
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>java.test.runner</groupId>
|
||||
<artifactId>junit4</artifactId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<name>junit4</name>
|
||||
<name>junit</name>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
@ -23,6 +23,30 @@
|
|||
<version>4.13.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>5.6.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.jqwik</groupId>
|
||||
<artifactId>jqwik</artifactId>
|
||||
<version>1.2.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cucumber</groupId>
|
||||
<artifactId>cucumber-java</artifactId>
|
||||
<version>5.6.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cucumber</groupId>
|
||||
<artifactId>cucumber-junit</artifactId>
|
||||
<version>5.6.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -1,4 +1,4 @@
|
|||
package junit5;
|
||||
package junit;
|
||||
|
||||
public class App {
|
||||
public String getGreeting() {
|
|
@ -10,6 +10,8 @@ import org.junit.jupiter.params.ParameterizedTest;
|
|||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import junit.App;
|
||||
|
||||
public class ParameterizedAnnotationTest {
|
||||
|
||||
// this is a comment
|
|
@ -1,3 +0,0 @@
|
|||
{
|
||||
"java.server.launchMode": "Standard"
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
plugins {
|
||||
id 'java'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter:5.6.0'
|
||||
testImplementation 'net.jqwik:jqwik:1.2.7'
|
||||
testImplementation 'io.cucumber:cucumber-java:5.6.0'
|
||||
testImplementation 'io.cucumber:cucumber-junit:5.6.0'
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform {
|
||||
includeEngines 'jqwik', 'junit-jupiter', 'junit-vintage'
|
||||
}
|
||||
|
||||
include '**/*Properties.class'
|
||||
include '**/*Test.class'
|
||||
include '**/*Tests.class'
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
/*
|
||||
* This file was generated by the Gradle 'init' task.
|
||||
*
|
||||
* The settings file is used to specify which projects to include in your build.
|
||||
*
|
||||
* Detailed information about configuring a multi-project build in Gradle can be found
|
||||
* in the user manual at https://docs.gradle.org/6.4.1/userguide/multi_project_builds.html
|
||||
*/
|
||||
|
||||
rootProject.name = 'junit5'
|
Загрузка…
Ссылка в новой задаче