Skip to content

Commit

Permalink
Additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mnoah1 committed Jul 2, 2024
1 parent adeaab3 commit f55a404
Show file tree
Hide file tree
Showing 4 changed files with 283 additions and 77 deletions.
10 changes: 8 additions & 2 deletions src/language-tools/java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export class JavaLanguageTools implements LanguageTools {
* @returns Lookup key to find this test case in the TestRunTracker.
*/
mapTestFinishDataToLookupKey(testFinishData: TestFinish): string | undefined {
if (testFinishData.dataKind === TestFinishDataKind.JUnitStyleTestCaseData) {
if (
testFinishData.dataKind === TestFinishDataKind.JUnitStyleTestCaseData &&
testFinishData.data
) {
const testCaseData = testFinishData.data as JUnitStyleTestCaseData
if (testCaseData.className !== undefined) {
let testCaseName = testFinishData.displayName
Expand All @@ -31,7 +34,10 @@ export class JavaLanguageTools implements LanguageTools {
testCaseName = match.groups.lookupKey
}

return `${testCaseData.className}.${testCaseName}`
// Use the class name as the base, and append the test case name if available.
let result = testCaseData.className
if (testCaseName.length > 0) result += `.${testCaseName}`
return result
} else {
return testFinishData.displayName
}
Expand Down
10 changes: 8 additions & 2 deletions src/language-tools/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export class PythonLanguageTools
* @returns Lookup key to find this test case in the TestRunTracker.
*/
mapTestFinishDataToLookupKey(testFinishData: TestFinish): string | undefined {
if (testFinishData.dataKind === TestFinishDataKind.JUnitStyleTestCaseData) {
if (
testFinishData.dataKind === TestFinishDataKind.JUnitStyleTestCaseData &&
testFinishData.data
) {
const testCaseData = testFinishData.data as JUnitStyleTestCaseData
let testCaseName = testFinishData.displayName

Expand All @@ -32,7 +35,10 @@ export class PythonLanguageTools
testCaseName = match.groups.lookupKey
}

return `${testCaseData.className}.${testCaseName}`
// Use the class name as the base, and append the test case name if available.
let result = testCaseData.className
if (testCaseName.length > 0) result += `.${testCaseName}`
return result
}
return undefined
}
Expand Down
174 changes: 139 additions & 35 deletions src/test/suite/language-tools/java.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,45 +99,149 @@ suite('Java Language Tools', () => {
assert.strictEqual(result.testCases.length, 0)
})

test('map test finish data to lookup key', async () => {
let result = languageTools.mapTestFinishDataToLookupKey({
displayName: 'myTest',
status: TestStatus.Failed,
dataKind: TestFinishDataKind.JUnitStyleTestCaseData,
data: {
time: 0,
className: 'com.example.ClassName',
const testCases = [
{
description: 'test method within a class',
input: {
displayName: 'myTest',
status: TestStatus.Failed,
dataKind: TestFinishDataKind.JUnitStyleTestCaseData,
data: {
time: 0,
className: 'com.example.ClassName',
},
},
})
assert.strictEqual(result, 'com.example.ClassName.myTest')

result = languageTools.mapTestFinishDataToLookupKey({
displayName: 'com.example.MySuite',
status: TestStatus.Failed,
dataKind: TestFinishDataKind.JUnitStyleTestCaseData,
data: {
time: 0,
expected: 'com.example.ClassName.myTest',
},
{
description: 'suite level test case',
input: {
displayName: 'com.example.MySuite',
status: TestStatus.Failed,
dataKind: TestFinishDataKind.JUnitStyleTestCaseData,
data: {
time: 0,
},
},
})
assert.strictEqual(result, 'com.example.MySuite')

result = languageTools.mapTestFinishDataToLookupKey({
displayName: 'com.example.MySuite',
status: TestStatus.Failed,
})
assert.strictEqual(result, undefined)

result = languageTools.mapTestFinishDataToLookupKey({
displayName: 'myTest[example1]',
status: TestStatus.Failed,
dataKind: TestFinishDataKind.JUnitStyleTestCaseData,
data: {
time: 0,
className: 'com.example.ClassName',
expected: 'com.example.MySuite',
},
{
description: 'no dataKind provided',
input: {
displayName: 'com.example.MySuite',
status: TestStatus.Failed,
},
expected: undefined,
},
{
description: 'parameterized test cases',
input: {
displayName: 'myTest[example1]',
status: TestStatus.Failed,
dataKind: TestFinishDataKind.JUnitStyleTestCaseData,
data: {
time: 0,
className: 'com.example.ClassName',
},
},
expected: 'com.example.ClassName.myTest',
},
{
description: 'successful tests with data',
input: {
displayName: 'mySuccessfulTest',
status: TestStatus.Passed,
dataKind: TestFinishDataKind.JUnitStyleTestCaseData,
data: {
time: 1,
className: 'com.example.SuccessClass',
},
},
expected: 'com.example.SuccessClass.mySuccessfulTest',
},
{
description: 'tests with no className',
input: {
displayName: 'myTestWithoutClass',
status: TestStatus.Failed,
dataKind: TestFinishDataKind.JUnitStyleTestCaseData,
data: {
time: 2,
},
},
expected: 'myTestWithoutClass',
},
{
description: 'unknown dataKind',
input: {
displayName: 'unknownTest',
status: TestStatus.Failed,
dataKind: 'UnknownDataKind',
data: {
time: 0,
className: 'com.example.UnknownClass',
},
},
expected: undefined,
},
// Remaining scenarios are unexpected, but should still return results.
{
description: 'null data gracefully',
input: {
displayName: 'nullDataTest',
status: TestStatus.Failed,
dataKind: TestFinishDataKind.JUnitStyleTestCaseData,
data: null,
},
expected: undefined,
},
{
description: 'numeric displayName',
input: {
displayName: '123456',
status: TestStatus.Failed,
dataKind: TestFinishDataKind.JUnitStyleTestCaseData,
data: {
time: 0,
className: 'com.example.ClassName',
},
},
expected: 'com.example.ClassName.123456',
},
{
description: 'special characters in displayName',
input: {
displayName: '!@#$%^&*()',
status: TestStatus.Failed,
dataKind: TestFinishDataKind.JUnitStyleTestCaseData,
data: {
time: 0,
className: 'com.example.ClassName',
},
},
expected: 'com.example.ClassName.!@#$%^&*()',
},
{
description: 'empty string as displayName',
input: {
displayName: '',
status: TestStatus.Failed,
dataKind: TestFinishDataKind.JUnitStyleTestCaseData,
data: {
time: 0,
className: 'com.example.ClassName',
},
},
expected: 'com.example.ClassName',
},
]

for (const testCase of testCases) {
test(`map test finish data to lookup key: ${testCase.description}`, async () => {
const result = languageTools.mapTestFinishDataToLookupKey(testCase.input)
assert.strictEqual(result, testCase.expected)
})
assert.strictEqual(result, 'com.example.ClassName.myTest')
})
}

test('map test case info to lookup key', async () => {
let testInfo = testController.createTestItem('test1', 'test1')
Expand Down
Loading

0 comments on commit f55a404

Please sign in to comment.