Skip to content

Commit 3bac1b1

Browse files
[Feature] Pass behavior type to dotnet test runner (#69)
* [Feature] Pass behavior field type to test cases * Add tests * version
1 parent 908fe83 commit 3bac1b1

File tree

9 files changed

+35
-9
lines changed

9 files changed

+35
-9
lines changed

Source/Machine.VSTestAdapter.Specs/Discovery/BuiltIn/When_discovering_behaviors.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,14 @@ public class When_discovering_specs_using_behaviors : With_DiscoverySetup<BuiltI
1919
discoveredSpec.LineNumber.ShouldEqual(14);
2020
discoveredSpec.CodeFilePath.EndsWith("BehaviorSample.cs", StringComparison.Ordinal);
2121
};
22+
23+
It should_pick_up_the_behavior_field_type_and_name = () => {
24+
MSpecTestCase discoveredSpec = Results.SingleOrDefault(x => "sample_behavior_test".Equals(x.SpecificationName, StringComparison.Ordinal) &&
25+
"BehaviorSampleSpec".Equals(x.ClassName, StringComparison.Ordinal));
26+
discoveredSpec.ShouldNotBeNull();
27+
28+
discoveredSpec.BehaviorFieldName.ShouldEqual("some_behavior");
29+
discoveredSpec.BehaviorFieldType.ShouldEqual("SampleSpecs.SampleBehavior");
30+
};
2231
}
2332
}

Source/Machine.VSTestAdapter.Specs/Machine.VSTestAdapter.Specs.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<ItemGroup>
99
<PackageReference Include="Machine.Fakes.Moq" Version="2.8.0" />
10-
<PackageReference Include="Machine.Specifications" Version="0.11.0" />
10+
<PackageReference Include="Machine.Specifications" Version="0.12.0" />
1111
<PackageReference Include="Machine.Specifications.Should" Version="0.11.0" />
1212
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
1313
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="15.0.0" Condition="'$(TargetFramework)'=='netstandard1.5'" />

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private IEnumerable<MSpecTestCase> CreateTestCase(Context context, string assemb
5858
}
5959

6060
if (spec is BehaviorSpecification behaviorSpec)
61-
testCase.BehaviorFieldName = GetBehaviorFieldName(behaviorSpec);
61+
PopulateBehaviorField(testCase, behaviorSpec);
6262

6363
if (context.Tags != null)
6464
testCase.Tags = context.Tags.Select(tag => tag.Name).ToArray();
@@ -70,12 +70,13 @@ private IEnumerable<MSpecTestCase> CreateTestCase(Context context, string assemb
7070
}
7171
}
7272

73-
private string GetBehaviorFieldName(BehaviorSpecification specification)
73+
private void PopulateBehaviorField(MSpecTestCase testCase, BehaviorSpecification specification)
7474
{
7575
if (behaviorProperty?.GetValue(specification) is FieldInfo field)
76-
return field.Name;
77-
78-
return string.Empty;
76+
{
77+
testCase.BehaviorFieldName = field.Name;
78+
testCase.BehaviorFieldType = field.FieldType.GenericTypeArguments.FirstOrDefault()?.FullName;
79+
}
7980
}
8081

8182
private string GetContextDisplayName(Type contextType)

Source/Machine.VSTestAdapter/Discovery/MSpecTestCase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class MSpecTestCase
1717
public string SpecificationDisplayName { get; set; }
1818
public string SpecificationName { get; set; }
1919
public string BehaviorFieldName { get; set; }
20+
public string BehaviorFieldType { get; set; }
2021

2122
public string CodeFilePath { get; set; }
2223

Source/Machine.VSTestAdapter/Helpers/SpecTestHelper.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public static TestCase GetVSTestCaseFromMSpecTestCase(string source, MSpecTestCa
3939
if (!string.IsNullOrEmpty(mspecTestCase.BehaviorFieldName))
4040
testCase.Traits.Add(new Trait(Strings.TRAIT_BEHAVIOR, mspecTestCase.BehaviorFieldName));
4141

42+
if (!string.IsNullOrEmpty(mspecTestCase.BehaviorFieldType))
43+
testCase.Traits.Add(new Trait(Strings.TRAIT_BEHAVIOR_TYPE, mspecTestCase.BehaviorFieldType));
44+
4245
Debug.WriteLine($"TestCase {testCase.FullyQualifiedName}");
4346
return testCase;
4447
}

Source/Machine.VSTestAdapter/Strings.Designer.cs

Lines changed: 9 additions & 0 deletions
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
@@ -147,6 +147,9 @@
147147
<data name="TRAIT_BEHAVIOR" xml:space="preserve">
148148
<value>BehaviorField</value>
149149
</data>
150+
<data name="TRAIT_BEHAVIOR_TYPE" xml:space="preserve">
151+
<value>BehaviorType</value>
152+
</data>
150153
<data name="TRAIT_CLASS" xml:space="preserve">
151154
<value>ClassName</value>
152155
</data>

Source/SampleSpecs/SampleSpecs.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Machine.Specifications" Version="0.11.0" />
9+
<PackageReference Include="Machine.Specifications" Version="0.12.0" />
1010
<PackageReference Include="Machine.Specifications.Should" Version="0.11.0" />
1111
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
1212
</ItemGroup>

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
environment:
2-
nuget_version: '2.4.0'
2+
nuget_version: '2.5.0'
33
nuget_prerelease: false
44
# vsix_version: '2.1.0'
5-
assembly_version: '2.4.0'
5+
assembly_version: '2.5.0'
66

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

0 commit comments

Comments
 (0)