Skip to content

Commit

Permalink
Merge pull request #65 from robertcoltheart/feature/expose-test-behav…
Browse files Browse the repository at this point in the history
…iors

[Feature] Detect behavior field names in test runner
  • Loading branch information
ivanz committed Oct 11, 2017
2 parents 646afdd + ac5b2d2 commit b1b2bc6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
12 changes: 12 additions & 0 deletions Source/Machine.VSTestAdapter/Discovery/BuiltIn/TestDiscoverer.cs
Expand Up @@ -15,6 +15,8 @@ public class TestDiscoverer
#endif
{

private readonly PropertyInfo behaviorProperty = typeof(BehaviorSpecification).GetProperty("BehaviorFieldInfo");

public IEnumerable<MSpecTestCase> DiscoverTests(string assemblyPath)
{
AssemblyExplorer assemblyExplorer = new AssemblyExplorer();
Expand Down Expand Up @@ -55,6 +57,8 @@ private IEnumerable<MSpecTestCase> 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();
Expand All @@ -66,6 +70,14 @@ private IEnumerable<MSpecTestCase> 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("_", " ");
Expand Down
1 change: 1 addition & 0 deletions Source/Machine.VSTestAdapter/Discovery/MSpecTestCase.cs
Expand Up @@ -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; }

Expand Down
3 changes: 3 additions & 0 deletions Source/Machine.VSTestAdapter/Helpers/SpecTestHelper.cs
Expand Up @@ -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;
}
Expand Down
11 changes: 10 additions & 1 deletion Source/Machine.VSTestAdapter/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Source/Machine.VSTestAdapter/Strings.resx
Expand Up @@ -144,6 +144,9 @@
<data name="RUNERROR" xml:space="preserve">
<value>Machine Specifications Visual Studio Test Adapter - Fatal error while executing test.</value>
</data>
<data name="TRAIT_BEHAVIOR" xml:space="preserve">
<value>BehaviorField</value>
</data>
<data name="TRAIT_CLASS" xml:space="preserve">
<value>ClassName</value>
</data>
Expand Down
8 changes: 4 additions & 4 deletions 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
Expand Down

0 comments on commit b1b2bc6

Please sign in to comment.