fix: Parameterized tests cannot be run when it's inner type (#1432)
Signed-off-by: sheche <sheche@microsoft.com>
This commit is contained in:
Родитель
332061a39e
Коммит
dd14c48b1b
|
@ -170,10 +170,13 @@ public class JUnitLaunchConfigurationDelegate extends org.eclipse.jdt.junit.laun
|
|||
if (obj instanceof SingleVariableDeclaration) {
|
||||
final ITypeBinding paramTypeBinding = ((SingleVariableDeclaration) obj)
|
||||
.getType().resolveBinding();
|
||||
if (paramTypeBinding.isParameterizedType()) {
|
||||
parameters.add(paramTypeBinding.getBinaryName());
|
||||
} else {
|
||||
if (paramTypeBinding == null) {
|
||||
throw new CoreException(new Status(IStatus.ERROR, JUnitPlugin.PLUGIN_ID, IStatus.ERROR,
|
||||
"Cannot set set argument for method" + methodDeclaration.toString(), null));
|
||||
} else if (paramTypeBinding.isPrimitive()) {
|
||||
parameters.add(paramTypeBinding.getQualifiedName());
|
||||
} else {
|
||||
parameters.add(paramTypeBinding.getBinaryName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { JavaTestRunnerDelegateCommands } from "../../src/constants";
|
||||
import { IJUnitLaunchArguments } from "../../src/runners/baseRunner/BaseRunner";
|
||||
import { TestKind, TestLevel } from "../../src/types";
|
||||
import { executeJavaLanguageServerCommand } from "../../src/utils/commandUtils";
|
||||
import { setupTestEnv } from "./utils";
|
||||
|
||||
// tslint:disable: only-arrow-functions
|
||||
// tslint:disable: no-object-literal-type-assertion
|
||||
suite('LaunchUtils Tests', () => {
|
||||
|
||||
suiteSetup(async function() {
|
||||
await setupTestEnv();
|
||||
});
|
||||
|
||||
test('Resolve JUnit 5 parameterized test 1', async () => {
|
||||
const argument: IJUnitLaunchArguments | undefined = await executeJavaLanguageServerCommand<IJUnitLaunchArguments>(
|
||||
JavaTestRunnerDelegateCommands.RESOLVE_JUNIT_ARGUMENT, JSON.stringify({
|
||||
projectName: 'junit',
|
||||
testLevel: TestLevel.Method,
|
||||
testKind: TestKind.JUnit5,
|
||||
testNames: ['=junit/src\\/test\\/java=/optional=/true=/=/maven.pomderived=/true=/=/test=/true=/<junit5{ParameterizedAnnotationTest.java[ParameterizedAnnotationTest~canRunWithComment~QString;~QBoolean;'],
|
||||
})
|
||||
);
|
||||
assert.strictEqual(
|
||||
argument?.programArguments[argument?.programArguments.length - 1],
|
||||
'junit5.ParameterizedAnnotationTest:canRunWithComment(java.lang.String,java.lang.Boolean)'
|
||||
);
|
||||
});
|
||||
|
||||
test('Resolve JUnit 5 parameterized test 2', async () => {
|
||||
const argument: IJUnitLaunchArguments | undefined = await executeJavaLanguageServerCommand<IJUnitLaunchArguments>(
|
||||
JavaTestRunnerDelegateCommands.RESOLVE_JUNIT_ARGUMENT, JSON.stringify({
|
||||
projectName: 'junit',
|
||||
testLevel: TestLevel.Method,
|
||||
testKind: TestKind.JUnit5,
|
||||
testNames: ['=junit/src\\/test\\/java=/optional=/true=/=/maven.pomderived=/true=/=/test=/true=/<junit5{ParameterizedAnnotationTest.java[ParameterizedAnnotationTest~equal~I~I'],
|
||||
})
|
||||
);
|
||||
assert.strictEqual(
|
||||
argument?.programArguments[argument?.programArguments.length - 1],
|
||||
'junit5.ParameterizedAnnotationTest:equal(int,int)'
|
||||
);
|
||||
});
|
||||
|
||||
test('Resolve JUnit 5 parameterized test 3', async () => {
|
||||
const argument: IJUnitLaunchArguments | undefined = await executeJavaLanguageServerCommand<IJUnitLaunchArguments>(
|
||||
JavaTestRunnerDelegateCommands.RESOLVE_JUNIT_ARGUMENT, JSON.stringify({
|
||||
projectName: 'junit',
|
||||
testLevel: TestLevel.Method,
|
||||
testKind: TestKind.JUnit5,
|
||||
testNames: ['=junit/src\\/test\\/java=/optional=/true=/=/maven.pomderived=/true=/=/test=/true=/<junit5{ParameterizedAnnotationTest.java[ParameterizedAnnotationTest~canRunWithGenericTypedParameter~QList\\<QInteger;>;'],
|
||||
})
|
||||
);
|
||||
assert.strictEqual(
|
||||
argument?.programArguments[argument?.programArguments.length - 1],
|
||||
'junit5.ParameterizedAnnotationTest:canRunWithGenericTypedParameter(java.util.List)'
|
||||
);
|
||||
});
|
||||
|
||||
test('Resolve JUnit 5 parameterized test 4', async () => {
|
||||
const argument: IJUnitLaunchArguments | undefined = await executeJavaLanguageServerCommand<IJUnitLaunchArguments>(
|
||||
JavaTestRunnerDelegateCommands.RESOLVE_JUNIT_ARGUMENT, JSON.stringify({
|
||||
projectName: 'junit',
|
||||
testLevel: TestLevel.Method,
|
||||
testKind: TestKind.JUnit5,
|
||||
testNames: ['=junit/src\\/test\\/java=/optional=/true=/=/maven.pomderived=/true=/=/test=/true=/<junit5{ParameterizedAnnotationTest.java[ParameterizedAnnotationTest~testCheckUser~QUser;'],
|
||||
})
|
||||
);
|
||||
assert.strictEqual(
|
||||
argument?.programArguments[argument?.programArguments.length - 1],
|
||||
'junit5.ParameterizedAnnotationTest:testCheckUser(junit5.ParameterizedAnnotationTest$User)'
|
||||
);
|
||||
});
|
||||
});
|
|
@ -7,6 +7,7 @@ import java.util.List;
|
|||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
|
@ -42,4 +43,15 @@ public class ParameterizedAnnotationTest {
|
|||
static Stream<List<Integer>> palindromeProvider() {
|
||||
return Stream.of(Collections.singletonList(1), Collections.singletonList(1));
|
||||
}
|
||||
|
||||
class User {}
|
||||
|
||||
static Stream<Arguments> users(){
|
||||
return Stream.of(Arguments.of(new ParameterizedAnnotationTest().new User()));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("users")
|
||||
public void testCheckUser(User user){
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче