diff --git a/Source/Machine.VSTestAdapter/Discovery/BuiltIn/TestDiscoverer.cs b/Source/Machine.VSTestAdapter/Discovery/BuiltIn/TestDiscoverer.cs index d720573..087c654 100644 --- a/Source/Machine.VSTestAdapter/Discovery/BuiltIn/TestDiscoverer.cs +++ b/Source/Machine.VSTestAdapter/Discovery/BuiltIn/TestDiscoverer.cs @@ -15,6 +15,8 @@ public class TestDiscoverer #endif { + private readonly PropertyInfo behaviorProperty = typeof(BehaviorSpecification).GetProperty("BehaviorFieldInfo"); + public IEnumerable DiscoverTests(string assemblyPath) { AssemblyExplorer assemblyExplorer = new AssemblyExplorer(); @@ -55,6 +57,8 @@ private IEnumerable CreateTestCase(Context context, string assemb testCase.LineNumber = locationInfo.LineNumber; } + if (spec is BehaviorSpecification behaviorSpec) + testCase.BehaviorFieldName = GetBehaviorFieldName(behaviorSpec); if (context.Tags != null) testCase.Tags = context.Tags.Select(tag => tag.Name).ToArray(); @@ -66,6 +70,14 @@ private IEnumerable CreateTestCase(Context context, string assemb } } + private string GetBehaviorFieldName(BehaviorSpecification specification) + { + if (behaviorProperty?.GetValue(specification) is FieldInfo field) + return field.Name; + + return string.Empty; + } + private string GetContextDisplayName(Type contextType) { var displayName = contextType.Name.Replace("_", " "); diff --git a/Source/Machine.VSTestAdapter/Discovery/MSpecTestCase.cs b/Source/Machine.VSTestAdapter/Discovery/MSpecTestCase.cs index 48afec6..2389cec 100644 --- a/Source/Machine.VSTestAdapter/Discovery/MSpecTestCase.cs +++ b/Source/Machine.VSTestAdapter/Discovery/MSpecTestCase.cs @@ -16,6 +16,7 @@ public class MSpecTestCase public string SpecificationDisplayName { get; set; } public string SpecificationName { get; set; } + public string BehaviorFieldName { get; set; } public string CodeFilePath { get; set; } diff --git a/Source/Machine.VSTestAdapter/Helpers/SpecTestHelper.cs b/Source/Machine.VSTestAdapter/Helpers/SpecTestHelper.cs index da3b229..d212e72 100644 --- a/Source/Machine.VSTestAdapter/Helpers/SpecTestHelper.cs +++ b/Source/Machine.VSTestAdapter/Helpers/SpecTestHelper.cs @@ -36,6 +36,9 @@ public static TestCase GetVSTestCaseFromMSpecTestCase(string source, MSpecTestCa } } + if (!string.IsNullOrEmpty(mspecTestCase.BehaviorFieldName)) + testCase.Traits.Add(new Trait(Strings.TRAIT_BEHAVIOR, mspecTestCase.BehaviorFieldName)); + Debug.WriteLine($"TestCase {testCase.FullyQualifiedName}"); return testCase; } diff --git a/Source/Machine.VSTestAdapter/Strings.Designer.cs b/Source/Machine.VSTestAdapter/Strings.Designer.cs index c27b243..9e68ddb 100644 --- a/Source/Machine.VSTestAdapter/Strings.Designer.cs +++ b/Source/Machine.VSTestAdapter/Strings.Designer.cs @@ -20,7 +20,7 @@ namespace Machine.VSTestAdapter { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Strings { @@ -142,6 +142,15 @@ internal static string RUNERROR { } } + /// + /// Looks up a localized string similar to BehaviorField. + /// + internal static string TRAIT_BEHAVIOR { + get { + return ResourceManager.GetString("TRAIT_BEHAVIOR", resourceCulture); + } + } + /// /// Looks up a localized string similar to ClassName. /// diff --git a/Source/Machine.VSTestAdapter/Strings.resx b/Source/Machine.VSTestAdapter/Strings.resx index 47a7164..2b1c00d 100644 --- a/Source/Machine.VSTestAdapter/Strings.resx +++ b/Source/Machine.VSTestAdapter/Strings.resx @@ -144,6 +144,9 @@ Machine Specifications Visual Studio Test Adapter - Fatal error while executing test. + + BehaviorField + ClassName diff --git a/appveyor.yml b/appveyor.yml index 64d7fe8..299d9ec 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,15 +1,15 @@ environment: - nuget_version: '2.3.0' - nuget_prerelease: false + nuget_version: '2.4.0-beta.1' + nuget_prerelease: true # vsix_version: '2.1.0' - assembly_version: '2.1.0' + assembly_version: '2.4.0' version: '$(nuget_version)+{build}' deploy: - provider: GitHub description: | - * Display line numbers and code file for .Net Core tests (#329) + * Support behavior field names for dotnet core projects on: appveyor_repo_tag: true