Skip to content

Commit

Permalink
Add support for test names that contain data
Browse files Browse the repository at this point in the history
In some cases test names include data in them. For e.g. when using xUnit you can create the so-called 'Theory' tests which run a given test with different inputs generated by a static method. In this case the test platform returns individual tests with different inputs. This commit fixes the parsing the logic to allow for such tests to be included in the test explorer.
  • Loading branch information
avranju committed Oct 22, 2017
1 parent 994dd8a commit 342a1c2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
28 changes: 17 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@
"main": "./out/src/extension",
"contributes": {
"views": {
"explorer": [{
"id": "dotnetTestExplorer",
"name": ".NET Test Explorer"
}]
"explorer": [
{
"id": "dotnetTestExplorer",
"name": ".NET Test Explorer"
}
]
},
"commands": [{
"commands": [
{
"command": "dotnet-test-explorer.refreshTestExplorer",
"title": "Refresh",
"icon": {
Expand All @@ -61,7 +64,8 @@
}
],
"menus": {
"view/title": [{
"view/title": [
{
"command": "dotnet-test-explorer.refreshTestExplorer",
"when": "view == dotnetTestExplorer",
"group": "navigation@1"
Expand All @@ -72,11 +76,13 @@
"group": "navigation@0"
}
],
"view/item/context": [{
"command": "dotnet-test-explorer.runTest",
"when": "view == dotnetTestExplorer",
"group": "dotnetTestExplorer@0"
}]
"view/item/context": [
{
"command": "dotnet-test-explorer.runTest",
"when": "view == dotnetTestExplorer",
"group": "dotnetTestExplorer@0"
}
]
},
"configuration": {
"type": "object",
Expand Down
9 changes: 7 additions & 2 deletions src/dotnetTestExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,13 @@ export class DotnetTestExplorer implements TreeDataProvider<TestNode> {
const structuredTests = {};

fullNames.forEach((name: string) => {
const parts = name.split(".");
this.addToObject(structuredTests, parts);
// this regex matches test names that include data in them - for e.g.
// Foo.Bar.BazTest(p1=10, p2="blah.bleh")
const match = /([^\(]+)(.*)/g.exec(name);
if (match && match.length > 1) {
const parts = match[1].split(".");
this.addToObject(structuredTests, parts);
}
});

const root = this.createTestNode("", structuredTests);
Expand Down

0 comments on commit 342a1c2

Please sign in to comment.