Skip to content

Commit de0b99c

Browse files
committed
Merge pull request #51 from ivanz/feature/friendly-test-name-in-ci
Feature/friendly test name in ci
2 parents d4c11fb + 1b17bd9 commit de0b99c

31 files changed

+281
-59
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Linq;
3+
using Machine.Fakes;
4+
using Machine.Specifications;
5+
using Machine.VSTestAdapter.Configuration;
6+
using Machine.VSTestAdapter.Discovery;
7+
using Machine.VSTestAdapter.Execution;
8+
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
9+
10+
namespace Machine.VSTestAdapter.Specs.Configuration
11+
{
12+
[Subject(typeof(Settings), "Configuration")]
13+
public class When_adapter_runs_tests : WithFakes
14+
{
15+
static string ConfigurationXml = @"<RunSettings>
16+
<RunConfiguration>
17+
<MaxCpuCount>0</MaxCpuCount>
18+
</RunConfiguration>
19+
<MSpec>
20+
<DisplayFullTestNameInOutput>true</DisplayFullTestNameInOutput>
21+
</MSpec>
22+
</RunSettings>";
23+
24+
static MSpecTestAdapter Adapter;
25+
26+
Establish establish = () => {
27+
The<IRunSettings>().WhenToldTo(runSettings => runSettings.SettingsXml).Return(ConfigurationXml);
28+
The<IRunContext>().WhenToldTo(context => context.RunSettings).Return(The<IRunSettings>());
29+
30+
Adapter = new MSpecTestAdapter(An<ISpecificationDiscoverer>(), The<ISpecificationExecutor>());
31+
};
32+
33+
34+
Because of = () => {
35+
Adapter.RunTests(new[] { "dll" }, The<IRunContext>(), An<IFrameworkHandle>());
36+
};
37+
38+
39+
It should_pick_up_DisplayFullTestName = () => {
40+
The<ISpecificationExecutor>().WasToldTo(d => d.RunAssembly("dll",
41+
Param<Settings>.Matches(s => s.DisplayFullTestNameInOutput == true),
42+
Param<Uri>.IsAnything,
43+
Param<IFrameworkHandle>.IsAnything));
44+
};
45+
46+
}
47+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Linq;
3+
using Machine.Specifications;
4+
using Machine.VSTestAdapter.Configuration;
5+
6+
namespace Machine.VSTestAdapter.Specs.Configuration
7+
{
8+
[Subject(typeof(Settings), "Configuration")]
9+
public class When_parsing_configuration_and_mspec_section_is_missing
10+
{
11+
static Settings Settings;
12+
static string ConfigurationXml = "<RunSettings></RunSettings>";
13+
14+
Because of = () => {
15+
Settings = Settings.Parse(ConfigurationXml);
16+
};
17+
18+
It should_default_to_DisplayFullTestName_off = () => {
19+
Settings.DisplayFullTestNameInOutput.ShouldBeFalse();
20+
};
21+
22+
}
23+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Machine.Specifications;
2+
using Machine.VSTestAdapter.Configuration;
3+
4+
namespace Machine.VSTestAdapter.Specs.Configuration
5+
{
6+
[Subject(typeof(Settings), "Configuration")]
7+
public class When_parsing_valid_configuration
8+
{
9+
static Settings Settings;
10+
static string ConfigurationXml = @"<RunSettings>
11+
<RunConfiguration>
12+
<MaxCpuCount>0</MaxCpuCount>
13+
</RunConfiguration>
14+
<MSpec>
15+
<DisplayFullTestNameInOutput>true</DisplayFullTestNameInOutput>
16+
</MSpec>
17+
</RunSettings>";
18+
19+
Because of = () => {
20+
Settings = Settings.Parse(ConfigurationXml);
21+
};
22+
23+
It should_pick_up_DisplayFullTestName = () => {
24+
Settings.DisplayFullTestNameInOutput.ShouldBeTrue();
25+
};
26+
27+
}
28+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class When_discovering_specs : With_DiscoverySetup<BuiltInSpecificationDi
1414
"StandardSpec".Equals(x.ClassName, StringComparison.Ordinal));
1515
discoveredSpec.ShouldNotBeNull();
1616

17+
discoveredSpec.SpecificationDisplayName.ShouldEqual("should pass");
1718
discoveredSpec.LineNumber.ShouldEqual(14);
1819
discoveredSpec.CodeFilePath.EndsWith("StandardSpec.cs", StringComparison.Ordinal);
1920
};
@@ -23,6 +24,7 @@ public class When_discovering_specs : With_DiscoverySetup<BuiltInSpecificationDi
2324
"StandardSpec".Equals(x.ClassName, StringComparison.Ordinal));
2425
discoveredSpec.ShouldNotBeNull();
2526

27+
discoveredSpec.SpecificationDisplayName.ShouldEqual("should be ignored");
2628
discoveredSpec.LineNumber.ShouldEqual(20);
2729
discoveredSpec.CodeFilePath.EndsWith("StandardSpec.cs", StringComparison.Ordinal);
2830
};
@@ -32,6 +34,7 @@ public class When_discovering_specs : With_DiscoverySetup<BuiltInSpecificationDi
3234
"StandardSpec".Equals(x.ClassName, StringComparison.Ordinal));
3335
discoveredSpec.ShouldNotBeNull();
3436

37+
discoveredSpec.SpecificationDisplayName.ShouldEqual("not implemented");
3538
discoveredSpec.LineNumber.ShouldEqual(0);
3639
discoveredSpec.CodeFilePath.ShouldBeNull();
3740
};

Source/Machine.VSTestAdapter.Specs/Execution/RunListener/When_specification_ends_with_a_fail.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Machine.Fakes;
77
using Machine.Specifications;
88
using Machine.Specifications.Runner;
9+
using Machine.VSTestAdapter.Configuration;
910
using Machine.VSTestAdapter.Execution;
1011
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
1112
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
@@ -26,7 +27,7 @@ public class When_specification_ends_with_a_fail : WithFakes
2627
.Callback((TestCase testCase, TestOutcome outcome) => TestCase = testCase);
2728

2829

29-
RunListener = new VSProxyAssemblySpecificationRunListener("assemblyPath", The<IFrameworkHandle>(), new Uri("bla://executorUri"));
30+
RunListener = new VSProxyAssemblySpecificationRunListener("assemblyPath", The<IFrameworkHandle>(), new Uri("bla://executorUri"), An<Settings>());
3031
};
3132

3233

Source/Machine.VSTestAdapter.Specs/Execution/RunListener/When_specification_ends_with_a_pass.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Machine.Fakes;
77
using Machine.Specifications;
88
using Machine.Specifications.Runner;
9+
using Machine.VSTestAdapter.Configuration;
910
using Machine.VSTestAdapter.Execution;
1011
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
1112
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
@@ -26,7 +27,7 @@ public class When_specification_ends_with_a_pass : WithFakes
2627
.Callback((TestCase testCase, TestOutcome outcome) => TestCase = testCase);
2728

2829

29-
RunListener = new VSProxyAssemblySpecificationRunListener("assemblyPath", The<IFrameworkHandle>(), new Uri("bla://executorUri"));
30+
RunListener = new VSProxyAssemblySpecificationRunListener("assemblyPath", The<IFrameworkHandle>(), new Uri("bla://executorUri"), An<Settings>());
3031
};
3132

3233

Source/Machine.VSTestAdapter.Specs/Execution/RunListener/When_specification_starts.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Machine.Fakes;
44
using Machine.Specifications;
55
using Machine.Specifications.Runner;
6+
using Machine.VSTestAdapter.Configuration;
67
using Machine.VSTestAdapter.Execution;
78
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
89
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
@@ -23,7 +24,7 @@ public class When_specification_starts : WithFakes
2324
.WhenToldTo(f => f.RecordStart(Param<TestCase>.IsAnything))
2425
.Callback((TestCase testCase) => TestCase = testCase);
2526

26-
RunListener = new VSProxyAssemblySpecificationRunListener("assemblyPath", The<IFrameworkHandle>(), new Uri("bla://executorUri"));
27+
RunListener = new VSProxyAssemblySpecificationRunListener("assemblyPath", The<IFrameworkHandle>(), new Uri("bla://executorUri"), An<Settings>());
2728
};
2829

2930

Source/Machine.VSTestAdapter.Specs/Execution/RunListener/When_there_is_an_error_reported.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Machine.Fakes;
77
using Machine.Specifications;
88
using Machine.Specifications.Runner;
9+
using Machine.VSTestAdapter.Configuration;
910
using Machine.VSTestAdapter.Execution;
1011
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
1112
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
@@ -20,7 +21,7 @@ public class When_there_is_an_error_reported : WithFakes
2021
static VSProxyAssemblySpecificationRunListener RunListener;
2122

2223
Establish context = () => {
23-
RunListener = new VSProxyAssemblySpecificationRunListener("assemblyPath", The<IFrameworkHandle>(), new Uri("bla://executorUri"));
24+
RunListener = new VSProxyAssemblySpecificationRunListener("assemblyPath", The<IFrameworkHandle>(), new Uri("bla://executorUri"), An<Settings>());
2425
};
2526

2627

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Machine.Fakes;
7+
using Machine.Specifications;
8+
using Machine.VSTestAdapter.Configuration;
9+
using Machine.VSTestAdapter.Helpers;
10+
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
11+
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
12+
13+
namespace Machine.VSTestAdapter.Specs.Execution
14+
{
15+
public class When_using_displayfulltestname_setting : With_SingleSpecExecutionSetup
16+
{
17+
static TestCase RecordStartTestCase;
18+
static TestCase RecordEndTestCase;
19+
20+
Establish context = () => {
21+
SpecificationToRun = new VisualStudioTestIdentifier("SampleSpecs.When_something", "should_pass");
22+
23+
The<Settings>().DisplayFullTestNameInOutput = true;
24+
25+
The<IFrameworkHandle>()
26+
.WhenToldTo(handle =>
27+
handle.RecordStart(Param<TestCase>.Matches(testCase => testCase.ToVisualStudioTestIdentifier().Equals(SpecificationToRun)))
28+
)
29+
.Callback((TestCase testCase) => RecordStartTestCase = testCase);
30+
31+
The<IFrameworkHandle>()
32+
.WhenToldTo(handle =>
33+
handle.RecordEnd(Param<TestCase>.Matches(testCase => testCase.ToVisualStudioTestIdentifier().Equals(SpecificationToRun)),
34+
Param<TestOutcome>.Matches(outcome => outcome == TestOutcome.Passed))
35+
)
36+
.Callback((TestCase testCase) => RecordEndTestCase = testCase);
37+
};
38+
39+
It should_display_both_the_context_name_and_specification_name_on_a_single_line = () => {
40+
RecordStartTestCase.DisplayName.ShouldEqual("SampleSpecs.When_something: should_pass");
41+
RecordEndTestCase.DisplayName.ShouldEqual("SampleSpecs.When_something: should_pass");
42+
};
43+
}
44+
}

Source/Machine.VSTestAdapter.Specs/Execution/With_AssemblyExecutionSetup.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.IO;
33
using Machine.Fakes;
44
using Machine.Specifications;
5+
using Machine.VSTestAdapter.Configuration;
56
using Machine.VSTestAdapter.Execution;
67
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
78

@@ -19,7 +20,7 @@ public abstract class With_AssemblyExecutionSetup : WithFakes
1920
};
2021

2122
Because of = () => {
22-
Executor.RunAssembly(AssemblyPath, new Uri("bla://executor"), An<IRunContext>(), The<IFrameworkHandle>());
23+
Executor.RunAssembly(AssemblyPath, An<Settings>(), new Uri("bla://executor"), The<IFrameworkHandle>());
2324
};
2425
}
2526
}

0 commit comments

Comments
 (0)