issue fix: test name is truncated when name contains rounded bracket(s) (#1071)

Co-authored-by: Sheng Chen <sheche@microsoft.com>
This commit is contained in:
Kang Liu 2020-10-14 08:39:09 +08:00 коммит произвёл GitHub
Родитель 7cc1ead170
Коммит 09caa1c7c5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 66 добавлений и 2 удалений

Просмотреть файл

@ -109,9 +109,10 @@ export class JUnitRunnerResultAnalyzer extends BaseRunnerResultAnalyzer {
* '(?:@AssumptionFailure: |@Ignore: )?' - indicate if the case is ignored due to assumption failure or disabled
* '(.*?)' - test method name
* '(?:\[\d+\])?' - execution index, it will appear for the JUnit4's parameterized test
* '\((.*?)\)' - class fully qualified name
* '\(([^)]*)\)[^(]*$' - class fully qualified name which wrapped by the last paired brackets, see:
* https://github.com/microsoft/vscode-java-test/issues/1075
*/
const regexp: RegExp = /\d+,(?:@AssumptionFailure: |@Ignore: )?(.*?)(?:\[\d+\])?\((.*?)\)/;
const regexp: RegExp = /\d+,(?:@AssumptionFailure: |@Ignore: )?(.*?)(?:\[\d+\])?\(([^)]*)\)[^(]*$/;
const matchResults: RegExpExecArray | null = regexp.exec(message);
if (matchResults && matchResults.length === 3) {
return `${this.projectName}@${matchResults[2]}#${matchResults[1]}`;

Просмотреть файл

@ -154,6 +154,36 @@ suite('Code Lens Tests', function() {
assert.ok(failedDetail!.duration !== undefined, 'Should have execution time');
});
test("Can run parameterized with name tests", async function() {
const document: TextDocument = await workspace.openTextDocument(Uris.JUNIT4_PARAMETERIZED_WITH_NAME_TEST);
await window.showTextDocument(document);
const codeLensProvider: TestCodeLensProvider = new TestCodeLensProvider();
const codeLens: CodeLens[] = await codeLensProvider.provideCodeLenses(document, Token.cancellationToken);
assert.equal(codeLens.length, 4, 'Code Lens should appear for @Test annotation');
const command: Command | undefined = codeLens[0].command;
assert.notEqual(command, undefined, 'Command inside Code Lens should not be undefined');
assert.notEqual(command, null, 'Command inside Code Lens should not be null');
const testItem: ITestItem[] = command!.arguments as ITestItem[];
assert.notEqual(testItem, undefined, 'Test Item inside Code Lens Command should not be undefined');
assert.notEqual(testItem, null, 'Test Item inside Code Lens Command should not be null');
assert.equal(testItem.length, 1, 'Test Item inside Code Lens Command should has one element');
await commands.executeCommand(command!.command, testItem[0]);
const projectName: string = testItem[0].project;
const passedDetail: ITestResult| undefined = testResultManager.getResultById(`${projectName}@junit4.ParameterizedWithNameTest#test[0: expect=1]`);
assert.equal(passedDetail!.status, TestStatus.Pass, 'Should have passed case');
assert.ok(passedDetail!.duration !== undefined, 'Should have execution time');
const failedDetail: ITestResult| undefined = testResultManager.getResultById(`${projectName}@junit4.ParameterizedWithNameTest#test[3: expect=()]`);
assert.equal(failedDetail!.status, TestStatus.Fail, 'Should have failed case');
assert.ok(failedDetail!.duration !== undefined, 'Should have execution time');
});
test("Assume failure should mark as skipped", async function() {
const document: TextDocument = await workspace.openTextDocument(Uris.JUNIT4_ASSUME_TEST);
await window.showTextDocument(document);

Просмотреть файл

@ -29,6 +29,7 @@ export namespace Uris {
export const JUNIT4_RUNWITH: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, JUNIT4_TEST_PACKAGE, 'RunWithAnnotation.java'));
export const JUNIT4_EXCEPTION_BEFORE: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, JUNIT4_TEST_PACKAGE, 'ExceptionInBefore.java'));
export const JUNIT4_PARAMETERIZED_TEST: Uri = Uri.file(path.join(TEST_PROJECT_BASE_PATH, JUNIT4_TEST_PACKAGE, 'ParameterizedTest.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'));
// Gradle modular

Просмотреть файл

@ -0,0 +1,32 @@
package junit4;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class ParameterizedWithNameTest {
@Parameter
public int expected;
@Parameters(name = "{index}: expect={0}")
public static Collection<Object> data() {
// If using the name annotation param and one of the inputs has a rounded
// bracket, e.g. @Parameters(name = "test({index})"), then the test name needs
// to be properly handled.
return Arrays.asList(1, 2, "normalString", "()", "(()");
}
@Test
public void test() {
assertEquals(expected, 1);
}
}