Skip to content

Commit b1b2bc6

Browse files
authored
Merge pull request #65 from robertcoltheart/feature/expose-test-behaviors
[Feature] Detect behavior field names in test runner
2 parents 646afdd + ac5b2d2 commit b1b2bc6

File tree

6 files changed

+33
-5
lines changed

6 files changed

+33
-5
lines changed

Source/Machine.VSTestAdapter/Discovery/BuiltIn/TestDiscoverer.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public class TestDiscoverer
1515
#endif
1616
{
1717

18+
private readonly PropertyInfo behaviorProperty = typeof(BehaviorSpecification).GetProperty("BehaviorFieldInfo");
19+
1820
public IEnumerable<MSpecTestCase> DiscoverTests(string assemblyPath)
1921
{
2022
AssemblyExplorer assemblyExplorer = new AssemblyExplorer();
@@ -55,6 +57,8 @@ private IEnumerable<MSpecTestCase> CreateTestCase(Context context, string assemb
5557
testCase.LineNumber = locationInfo.LineNumber;
5658
}
5759

60+
if (spec is BehaviorSpecification behaviorSpec)
61+
testCase.BehaviorFieldName = GetBehaviorFieldName(behaviorSpec);
5862

5963
if (context.Tags != null)
6064
testCase.Tags = context.Tags.Select(tag => tag.Name).ToArray();
@@ -66,6 +70,14 @@ private IEnumerable<MSpecTestCase> CreateTestCase(Context context, string assemb
6670
}
6771
}
6872

73+
private string GetBehaviorFieldName(BehaviorSpecification specification)
74+
{
75+
if (behaviorProperty?.GetValue(specification) is FieldInfo field)
76+
return field.Name;
77+
78+
return string.Empty;
79+
}
80+
6981
private string GetContextDisplayName(Type contextType)
7082
{
7183
var displayName = contextType.Name.Replace("_", " ");

Source/Machine.VSTestAdapter/Discovery/MSpecTestCase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class MSpecTestCase
1616

1717
public string SpecificationDisplayName { get; set; }
1818
public string SpecificationName { get; set; }
19+
public string BehaviorFieldName { get; set; }
1920

2021
public string CodeFilePath { get; set; }
2122

Source/Machine.VSTestAdapter/Helpers/SpecTestHelper.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public static TestCase GetVSTestCaseFromMSpecTestCase(string source, MSpecTestCa
3636
}
3737
}
3838

39+
if (!string.IsNullOrEmpty(mspecTestCase.BehaviorFieldName))
40+
testCase.Traits.Add(new Trait(Strings.TRAIT_BEHAVIOR, mspecTestCase.BehaviorFieldName));
41+
3942
Debug.WriteLine($"TestCase {testCase.FullyQualifiedName}");
4043
return testCase;
4144
}

Source/Machine.VSTestAdapter/Strings.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/Machine.VSTestAdapter/Strings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@
144144
<data name="RUNERROR" xml:space="preserve">
145145
<value>Machine Specifications Visual Studio Test Adapter - Fatal error while executing test.</value>
146146
</data>
147+
<data name="TRAIT_BEHAVIOR" xml:space="preserve">
148+
<value>BehaviorField</value>
149+
</data>
147150
<data name="TRAIT_CLASS" xml:space="preserve">
148151
<value>ClassName</value>
149152
</data>

appveyor.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
environment:
2-
nuget_version: '2.3.0'
3-
nuget_prerelease: false
2+
nuget_version: '2.4.0-beta.1'
3+
nuget_prerelease: true
44
# vsix_version: '2.1.0'
5-
assembly_version: '2.1.0'
5+
assembly_version: '2.4.0'
66

77
version: '$(nuget_version)+{build}'
88

99
deploy:
1010
- provider: GitHub
1111
description: |
12-
* Display line numbers and code file for .Net Core tests (#329)
12+
* Support behavior field names for dotnet core projects
1313
1414
on:
1515
appveyor_repo_tag: true

0 commit comments

Comments
 (0)