test: Refactor the test code (#1170)
This commit is contained in:
Родитель
406e9f876f
Коммит
39602e7e85
|
@ -107,9 +107,8 @@ jobs:
|
||||||
- name: Build OSGi bundle
|
- name: Build OSGi bundle
|
||||||
run: npm run build-plugin
|
run: npm run build-plugin
|
||||||
|
|
||||||
# TODO: Enable the darwin build after figure out how to stop Gradle Daemon
|
- name: Test extension
|
||||||
# - name: Test extension
|
run: npm test
|
||||||
# run: npm test
|
|
||||||
|
|
||||||
- name: Print language server Log if job failed
|
- name: Print language server Log if job failed
|
||||||
if: ${{ failure() }}
|
if: ${{ failure() }}
|
||||||
|
|
|
@ -25,11 +25,11 @@
|
||||||
"projectName": "com.microsoft.java.test.plugin",
|
"projectName": "com.microsoft.java.test.plugin",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Launch Tests (webpack) - Maven JUnit4 Code Lens",
|
"name": "Launch Tests (webpack) - Maven JUnit",
|
||||||
"type": "extensionHost",
|
"type": "extensionHost",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"runtimeExecutable": "${execPath}",
|
"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,
|
"sourceMaps": true,
|
||||||
"outFiles": [ "${workspaceFolder}/dist/**/*.js" ],
|
"outFiles": [ "${workspaceFolder}/dist/**/*.js" ],
|
||||||
"preLaunchTask": "npm: compile"
|
"preLaunchTask": "npm: compile"
|
||||||
|
@ -43,16 +43,6 @@
|
||||||
"sourceMaps": true,
|
"sourceMaps": true,
|
||||||
"outFiles": [ "${workspaceFolder}/dist/**/*.js" ],
|
"outFiles": [ "${workspaceFolder}/dist/**/*.js" ],
|
||||||
"preLaunchTask": "npm: compile"
|
"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": {
|
"@sinonjs/commons": {
|
||||||
"version": "1.8.2",
|
"version": "1.8.3",
|
||||||
"resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.2.tgz",
|
"resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.3.tgz",
|
||||||
"integrity": "sha512-sruwd86RJHdsVf/AtBoijDmUqJp3B6hF/DGC23C+JaegnDHaZyewCjoVGTdg3J0uz3Zs7NnIT05OBOmML72lQw==",
|
"integrity": "sha512-xkNcLAn/wZaX14RPlwizcKicDk9G3F8m2nU3L7Ukm5zBgTwiT0wsoFAHx9Jq56fJA1z/7uKGtCRu16sOUCLIHQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"type-detect": "4.0.8"
|
"type-detect": "4.0.8"
|
||||||
|
@ -3901,9 +3901,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"hosted-git-info": {
|
"hosted-git-info": {
|
||||||
"version": "2.8.8",
|
"version": "2.8.9",
|
||||||
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.8.tgz",
|
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz",
|
||||||
"integrity": "sha512-f/wzC2QaWBs7t9IYqB4T3sR1xviIViXJRJTWBlx2Gf3g0Xi5vI7Yy4koXQ1c9OYDGHN9sBy1DQ2AB8fqZBWhUg==",
|
"integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"http-proxy-agent": {
|
"http-proxy-agent": {
|
||||||
|
@ -5466,9 +5466,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"y18n": {
|
"y18n": {
|
||||||
"version": "4.0.2",
|
"version": "4.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz",
|
||||||
"integrity": "sha512-DnBDwcL54b5xWMM/7RfFg4xs5amYxq2ot49aUfLjQSAracXkGvlZq0txzqr3Pa6Q0ayuCxBcwTzrPUScKY0O8w==",
|
"integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"yargs": {
|
"yargs": {
|
||||||
|
@ -6972,9 +6972,9 @@
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"repeat-element": {
|
"repeat-element": {
|
||||||
"version": "1.1.3",
|
"version": "1.1.4",
|
||||||
"resolved": "https://registry.npmjs.org/repeat-element/-/repeat-element-1.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/repeat-element/-/repeat-element-1.1.4.tgz",
|
||||||
"integrity": "sha512-ahGq0ZnV5m5XtZLMb+vP76kcAM5nkLqk0lpqAuojSKGgQtn4eRi4ZZGm2olo2zKFH+sMsWaqOCW1dqAnOru72g==",
|
"integrity": "sha512-LFiNfRcSu7KK3evMyYOuCzv3L10TW7yC1G2/+StMjK8Y6Vqd2MG7r/Qjw4ghtuCOjFvlnms/iMmLqpvW/ES/WQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"repeat-string": {
|
"repeat-string": {
|
||||||
|
@ -7301,9 +7301,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"y18n": {
|
"y18n": {
|
||||||
"version": "4.0.2",
|
"version": "4.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz",
|
||||||
"integrity": "sha512-DnBDwcL54b5xWMM/7RfFg4xs5amYxq2ot49aUfLjQSAracXkGvlZq0txzqr3Pa6Q0ayuCxBcwTzrPUScKY0O8w==",
|
"integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"yargs": {
|
"yargs": {
|
||||||
|
@ -8254,18 +8254,18 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ssri": {
|
"ssri": {
|
||||||
"version": "6.0.1",
|
"version": "6.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/ssri/-/ssri-6.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/ssri/-/ssri-6.0.2.tgz",
|
||||||
"integrity": "sha512-3Wge10hNcT1Kur4PDFwEieXSCMCJs/7WvSACcrMYrNp+b8kDL1/0wJch5Ni2WrtwEa2IO8OsVfeKIciKCDx/QA==",
|
"integrity": "sha512-cepbSq/neFK7xB6A50KHN0xHDotYzq58wWCa5LeWqnPrHG8GzfEjO/4O8kpmcGW+oaxkvhEJCWgbgNk4/ZV93Q==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"figgy-pudding": "^3.5.1"
|
"figgy-pudding": "^3.5.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"y18n": {
|
"y18n": {
|
||||||
"version": "4.0.2",
|
"version": "4.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz",
|
||||||
"integrity": "sha512-DnBDwcL54b5xWMM/7RfFg4xs5amYxq2ot49aUfLjQSAracXkGvlZq0txzqr3Pa6Q0ayuCxBcwTzrPUScKY0O8w==",
|
"integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"yallist": {
|
"yallist": {
|
||||||
|
@ -9669,9 +9669,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"y18n": {
|
"y18n": {
|
||||||
"version": "4.0.2",
|
"version": "4.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz",
|
||||||
"integrity": "sha512-DnBDwcL54b5xWMM/7RfFg4xs5amYxq2ot49aUfLjQSAracXkGvlZq0txzqr3Pa6Q0ayuCxBcwTzrPUScKY0O8w==",
|
"integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"yargs": {
|
"yargs": {
|
||||||
|
@ -10024,9 +10024,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"y18n": {
|
"y18n": {
|
||||||
"version": "4.0.2",
|
"version": "4.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz",
|
||||||
"integrity": "sha512-DnBDwcL54b5xWMM/7RfFg4xs5amYxq2ot49aUfLjQSAracXkGvlZq0txzqr3Pa6Q0ayuCxBcwTzrPUScKY0O8w==",
|
"integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"yargs": {
|
"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 * as assert from 'assert';
|
||||||
import { CodeLens, Command, commands, TextDocument, window, workspace } from 'vscode';
|
import { CodeLens, Command, commands, TextDocument, window, workspace } from 'vscode';
|
||||||
import { ITestResult, TestCodeLensProvider, testResultManager, ITestItem } from '../../extension.bundle';
|
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;
|
let javaVersion: number = -1;
|
||||||
|
|
||||||
suiteSetup(async function() {
|
suiteSetup(async function() {
|
||||||
|
setupTestEnv();
|
||||||
javaVersion = await getJavaVersion();
|
javaVersion = await getJavaVersion();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
import * as cp from 'child_process';
|
import * as cp from 'child_process';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import { downloadAndUnzipVSCode, resolveCliPathFromVSCodeExecutablePath, runTests } from 'vscode-test';
|
import { downloadAndUnzipVSCode, resolveCliPathFromVSCodeExecutablePath, runTests } from 'vscode-test';
|
||||||
|
import * as util from 'util';
|
||||||
|
|
||||||
async function main(): Promise<void> {
|
async function main(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
|
@ -24,15 +25,16 @@ async function main(): Promise<void> {
|
||||||
stdio: 'inherit',
|
stdio: 'inherit',
|
||||||
});
|
});
|
||||||
|
|
||||||
// Run Maven JUnit 4 Code Lens tests
|
// Run Maven JUnit tests
|
||||||
await runTests({
|
await runTests({
|
||||||
vscodeExecutablePath,
|
vscodeExecutablePath,
|
||||||
extensionDevelopmentPath,
|
extensionDevelopmentPath,
|
||||||
extensionTestsPath: path.resolve(__dirname, './maven-junit4-suite'),
|
extensionTestsPath: path.resolve(__dirname, './maven-junit-suite'),
|
||||||
launchArgs: [
|
launchArgs: [
|
||||||
path.join(__dirname, '..', '..', 'test', 'test-projects', 'junit4'),
|
path.join(__dirname, '..', '..', 'test', 'test-projects', 'junit'),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
await killJavaProcess();
|
||||||
|
|
||||||
// Run Gradle modular project tests
|
// Run Gradle modular project tests
|
||||||
await runTests({
|
await runTests({
|
||||||
|
@ -43,21 +45,26 @@ async function main(): Promise<void> {
|
||||||
path.join(__dirname, '..', '..', 'test', 'test-projects', 'modular-gradle'),
|
path.join(__dirname, '..', '..', 'test', 'test-projects', 'modular-gradle'),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
await killJavaProcess();
|
||||||
// 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'),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to run tests');
|
console.error('Failed to run tests');
|
||||||
process.exit(1);
|
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();
|
main();
|
||||||
|
|
||||||
|
|
|
@ -3,14 +3,14 @@
|
||||||
|
|
||||||
import * as assert from 'assert';
|
import * as assert from 'assert';
|
||||||
import * as path from "path";
|
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 { searchTestLocation, ILocation } from '../../extension.bundle';
|
||||||
import { Uris } from '../shared';
|
import { setupTestEnv, Uris } from '../shared';
|
||||||
|
|
||||||
suite('Command Utils Tests', function() {
|
suite('Command Utils Tests', function() {
|
||||||
|
|
||||||
suiteSetup(async function() {
|
suiteSetup(async function() {
|
||||||
await extensions.getExtension('vscjava.vscode-java-test')!.activate();
|
setupTestEnv()
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Can search location for <TestError> items", async function() {
|
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.
|
// Licensed under the MIT license.
|
||||||
|
|
||||||
import * as assert from 'assert';
|
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 { 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() {
|
suite('Code Lens Tests', function() {
|
||||||
|
|
||||||
suiteSetup(async 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() {
|
test("Code Lens should work for JUnit 4's @Test annotation", async function() {
|
|
@ -3,18 +3,18 @@
|
||||||
|
|
||||||
import * as assert from 'assert';
|
import * as assert from 'assert';
|
||||||
import * as fse from 'fs-extra';
|
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 { 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() {
|
suite('Code Lens Tests', function() {
|
||||||
|
|
||||||
suiteSetup(async 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() {
|
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);
|
await window.showTextDocument(document);
|
||||||
|
|
||||||
const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider();
|
const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider();
|
||||||
|
@ -38,7 +38,7 @@ suite('Code Lens Tests', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Can get correct result", async 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);
|
await window.showTextDocument(document);
|
||||||
|
|
||||||
const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider();
|
const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider();
|
||||||
|
@ -58,7 +58,7 @@ suite('Code Lens Tests', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Can run test with generic typed parameter", async 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);
|
await window.showTextDocument(document);
|
||||||
|
|
||||||
const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider();
|
const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider();
|
||||||
|
@ -77,7 +77,7 @@ suite('Code Lens Tests', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Can run test method annotated with @Testable", async 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);
|
await window.showTextDocument(document);
|
||||||
|
|
||||||
const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider();
|
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() {
|
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);
|
await window.showTextDocument(document);
|
||||||
|
|
||||||
const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider();
|
const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider();
|
||||||
|
@ -110,7 +110,7 @@ suite('Code Lens Tests', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Can run test method annotated with @Nested", async 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);
|
await window.showTextDocument(document);
|
||||||
|
|
||||||
const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider();
|
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() {
|
test("Can correctly update the test results for cucumber tests", async function() {
|
||||||
const document: TextDocument = await workspace.openTextDocument(Uris.GRADLE_CUCUMBER_TEST);
|
const fileContent: string = await fse.readFile(Uris.CUCUMBER_STEP.fsPath, 'utf-8');
|
||||||
await window.showTextDocument(document);
|
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();
|
await commands.executeCommand('java.test.relaunch');
|
||||||
const codeLens: CodeLens[] = await codeLensProvider.provideCodeLenses(document, Token.cancellationToken);
|
result = testResultManager.getResultById(`${projectName}@The calculator application#client wants to add 2 numbers`);
|
||||||
|
assert.strictEqual(result!.status, TestStatus.Pass);
|
||||||
const command: Command | undefined = codeLens[0].command;
|
} finally {
|
||||||
|
// revert the file change
|
||||||
const testItem: ITestItem[] = command!.arguments as ITestItem[];
|
await fse.writeFile(Uris.CUCUMBER_STEP.fsPath, fileContent, {encoding: 'utf-8'});
|
||||||
|
}
|
||||||
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'});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
teardown(async function() {
|
teardown(async function() {
|
|
@ -2,23 +2,23 @@
|
||||||
// Licensed under the MIT license.
|
// Licensed under the MIT license.
|
||||||
|
|
||||||
import * as assert from 'assert';
|
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 { testResultManager, ITestResult, TestStatus } from '../../extension.bundle';
|
||||||
import { Uris } from '../shared';
|
import { setupTestEnv, Uris } from '../shared';
|
||||||
|
|
||||||
suite('Run from Editor Tests', function() {
|
suite('Run from Editor Tests', function() {
|
||||||
|
|
||||||
suiteSetup(async function() {
|
suiteSetup(async function() {
|
||||||
await extensions.getExtension('vscjava.vscode-java-test')!.activate();
|
setupTestEnv();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Can run from active editor", async function() {
|
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 window.showTextDocument(document);
|
||||||
|
|
||||||
await commands.executeCommand('java.test.editor.run');
|
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);
|
assert.strictEqual(detail!.status, TestStatus.Pass);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,26 +1,26 @@
|
||||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
// Licensed under the MIT license.
|
// Licensed under the MIT license.
|
||||||
|
|
||||||
import { commands, extensions, RelativePattern } from 'vscode';
|
import { commands, RelativePattern } from 'vscode';
|
||||||
import { testCodeLensController, testFileWatcher } from '../../extension.bundle';
|
import { testCodeLensController, testFileWatcher } from '../../extension.bundle';
|
||||||
import * as assert from 'assert';
|
import * as assert from 'assert';
|
||||||
import * as sinon from 'sinon';
|
import * as sinon from 'sinon';
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import { Uris } from '../shared';
|
import { setupTestEnv, Uris } from '../shared';
|
||||||
|
|
||||||
suite('Test File Watcher Tests', function() {
|
suite('Test File Watcher Tests', function() {
|
||||||
|
|
||||||
const sandbox = sinon.createSandbox();
|
const sandbox = sinon.createSandbox();
|
||||||
|
|
||||||
suiteSetup(async function() {
|
suiteSetup(async function() {
|
||||||
await extensions.getExtension('vscjava.vscode-java-test')!.activate();
|
setupTestEnv();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Should correctly setup code lens provider", async function() {
|
test("Should correctly setup code lens provider", async function() {
|
||||||
let spy: sinon.SinonSpy = sandbox.spy(testCodeLensController, 'registerCodeLensProvider');
|
let spy: sinon.SinonSpy = sandbox.spy(testCodeLensController, 'registerCodeLensProvider');
|
||||||
await testFileWatcher.registerListeners();
|
await testFileWatcher.registerListeners();
|
||||||
const args: RelativePattern[] = spy.getCall(0).args[0];
|
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, '..')));
|
assert.ok(path.relative(args[0].base, path.join(Uris.JUNIT4_TEST_PACKAGE, '..')));
|
||||||
spy.restore();
|
spy.restore();
|
||||||
});
|
});
|
|
@ -2,25 +2,25 @@
|
||||||
// Licensed under the MIT license.
|
// Licensed under the MIT license.
|
||||||
|
|
||||||
import * as assert from 'assert';
|
import * as assert from 'assert';
|
||||||
import { commands, window, extensions } from 'vscode';
|
import { commands, window } from 'vscode';
|
||||||
import { Uris } from '../shared';
|
import { setupTestEnv, Uris } from '../shared';
|
||||||
|
|
||||||
suite('Test Report Tests', function() {
|
suite('Test Report Tests', function() {
|
||||||
|
|
||||||
suiteSetup(async function() {
|
suiteSetup(async function() {
|
||||||
await extensions.getExtension('vscjava.vscode-java-test')!.activate();
|
setupTestEnv();
|
||||||
await commands.executeCommand('workbench.action.closeActiveEditor');
|
await commands.executeCommand('workbench.action.closeActiveEditor');
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Can open test source location from uri and range", async function() {
|
test("Can open test source location from uri and range", async function() {
|
||||||
await commands.executeCommand(
|
await commands.executeCommand(
|
||||||
'java.test.report.openTestSourceLocation',
|
'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}}',
|
'{"start":{"line":30,"character":16},"end":{"line":30,"character":21}}',
|
||||||
undefined,
|
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);
|
assert.strictEqual(window.activeTextEditor?.selection.start.line, 30);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -29,18 +29,18 @@ suite('Test Report Tests', function() {
|
||||||
'java.test.report.openTestSourceLocation',
|
'java.test.report.openTestSourceLocation',
|
||||||
undefined,
|
undefined,
|
||||||
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?.document.uri.fsPath, Uris.JUNIT5_PARAMETERIZED_TEST.fsPath);
|
||||||
assert.strictEqual(window.activeTextEditor?.selection.start.line, 30);
|
assert.strictEqual(window.activeTextEditor?.selection.start.line, 32);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Can open test source location from stack trace", async function() {
|
test("Can open test source location from stack trace", async function() {
|
||||||
await commands.executeCommand(
|
await commands.executeCommand(
|
||||||
'java.test.report.openStackTrace',
|
'java.test.report.openStackTrace',
|
||||||
'at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:55)',
|
'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'));
|
assert.ok(window.activeTextEditor?.document.uri.fsPath.endsWith('AssertionUtils.class'));
|
|
@ -2,7 +2,8 @@
|
||||||
// Licensed under the MIT license.
|
// Licensed under the MIT license.
|
||||||
|
|
||||||
import * as path from 'path';
|
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 {
|
interface IDisposable {
|
||||||
dispose(): void;
|
dispose(): void;
|
||||||
|
@ -21,9 +22,9 @@ export namespace Token {
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace Uris {
|
export namespace Uris {
|
||||||
// JUnit 4
|
// JUnit
|
||||||
const TEST_PROJECT_BASE_PATH: string = path.join(__dirname, '..', '..', 'test', 'test-projects');
|
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_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_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'));
|
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_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'));
|
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
|
// Gradle modular
|
||||||
const MODULAR_GRADLE: string = path.join('modular-gradle', 'src', 'test', 'java', 'com', 'example', 'project');
|
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'));
|
export const MODULAR_GRADLE_TEST: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, MODULAR_GRADLE, 'GradleModularTest.java'));
|
||||||
|
}
|
||||||
|
|
||||||
// Gradle JUnit5
|
export async function setupTestEnv() {
|
||||||
const GRADLE_JUNIT5_TEST_PACKAGE: string = path.join('junit5', 'src', 'test', 'java', 'junit5');
|
await extensions.getExtension("redhat.java")!.activate();
|
||||||
export const GRADLE_JUNIT5_PARAMETERIZED_TEST: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, GRADLE_JUNIT5_TEST_PACKAGE, 'ParameterizedAnnotationTest.java'));
|
const javaExt = extensions.getExtension("redhat.java");
|
||||||
export const GRADLE_JUNIT5_NESTED_TEST: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, GRADLE_JUNIT5_TEST_PACKAGE, 'NestedTest.java'));
|
await javaExt!.activate();
|
||||||
export const GRADLE_JUNIT5_META_ANNOTATION_TEST: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, GRADLE_JUNIT5_TEST_PACKAGE, 'MetaAnnotationTest.java'));
|
const api = javaExt?.exports;
|
||||||
export const GRADLE_JUNIT5_PROPERTY_TEST: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, GRADLE_JUNIT5_TEST_PACKAGE, 'PropertyTest.java'));
|
while (api.serverMode !== "Standard") {
|
||||||
export const GRADLE_CUCUMBER_TEST: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, GRADLE_JUNIT5_TEST_PACKAGE, 'cucumber', 'CucumberTest.java'));
|
await sleep(2 * 1000/*ms*/);
|
||||||
export const GRADLE_CUCUMBER_STEP: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, GRADLE_JUNIT5_TEST_PACKAGE, 'cucumber', 'CucumberSteps.java'));
|
}
|
||||||
|
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> {
|
export async function getJavaVersion(): Promise<number> {
|
||||||
|
|
|
@ -5,10 +5,10 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>java.test.runner</groupId>
|
<groupId>java.test.runner</groupId>
|
||||||
<artifactId>junit4</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
<name>junit4</name>
|
<name>junit</name>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
@ -23,6 +23,30 @@
|
||||||
<version>4.13.1</version>
|
<version>4.13.1</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</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>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -1,4 +1,4 @@
|
||||||
package junit5;
|
package junit;
|
||||||
|
|
||||||
public class App {
|
public class App {
|
||||||
public String getGreeting() {
|
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.CsvSource;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
|
||||||
|
import junit.App;
|
||||||
|
|
||||||
public class ParameterizedAnnotationTest {
|
public class ParameterizedAnnotationTest {
|
||||||
|
|
||||||
// this is a comment
|
// 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'
|
|
Загрузка…
Ссылка в новой задаче