Skip to content

Commit 62f126d

Browse files
committed
Always set UseDedicatedTestResultsDirectory to true, because #if CI_BUILD isn't really the desired behavior
1 parent 9011b89 commit 62f126d

2 files changed

Lines changed: 32 additions & 17 deletions

File tree

src/Dibix.Testing/TestBase.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected TConfiguration Configuration
2929

3030
protected override Task OnTestInitialized()
3131
{
32-
this.Configuration = TestConfigurationLoader.Load<TConfiguration>(this.TestContext);
32+
this.Configuration = TestConfigurationLoader.Load<TConfiguration>(base.TestContext);
3333
return Task.CompletedTask;
3434
}
3535
}
@@ -58,17 +58,7 @@ internal TestOutputWriter TestOutputHelper
5858
protected virtual TextWriter Out => this.TestOutputHelper;
5959
protected string RunDirectory => this.TestResultComposer.RunDirectory;
6060
protected string TestDirectory => this.TestResultComposer.TestDirectory;
61-
62-
/// <summary>
63-
/// By default, the test results directory is cleaned up by MSTest, after all tests of a run have passed.
64-
/// It might be desired to keep the test output even if all tests have passed, i.E. for investigation purposes.
65-
/// Setting this property to true, will store the output in the temp directory, so they are still available after each run.
66-
/// </summary>
67-
#if CI_BUILD
6861
protected virtual bool UseDedicatedTestResultsDirectory => true;
69-
#else
70-
protected virtual bool UseDedicatedTestResultsDirectory => false;
71-
#endif
7262
private TestResultComposer TestResultComposer
7363
{
7464
get => SafeGetProperty(ref this._testResultComposer);
@@ -219,8 +209,8 @@ protected virtual void Dispose(bool disposing)
219209
{
220210
if (disposing)
221211
{
222-
this.TestOutputHelper?.Dispose();
223-
TestResultComposer.Complete();
212+
this._testOutputHelper?.Dispose();
213+
this._testResultComposer?.Complete();
224214
}
225215
}
226216
#endregion

src/Dibix.Testing/Utilities/TestResultComposer.cs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using System.Linq;
77
using System.Reflection;
88
using Microsoft.VisualStudio.TestTools.UnitTesting;
9+
using Newtonsoft.Json;
10+
using Newtonsoft.Json.Serialization;
911

1012
namespace Dibix.Testing
1113
{
@@ -36,6 +38,9 @@ public TestResultComposer(TestContext testContext, bool useDedicatedTestResultsD
3638
this._actualDirectory = Path.Combine(this.RunDirectory, ActualDirectoryName);
3739
this._testRunFiles = new HashSet<string>();
3840
this._testFiles = new HashSet<string>();
41+
#if DEBUG
42+
this.EnsureTestContextDump();
43+
#endif
3944
}
4045

4146
public string AddFile(string fileName)
@@ -136,16 +141,22 @@ private void RegisterFile(string path, bool scopeIsTestRun)
136141
files.Add(path);
137142
}
138143

139-
private void EnsureWinMergeStarter()
144+
private void EnsureWinMergeStarter() => AddTestRunFile("winmerge.bat", $@"@echo off
145+
start winmergeU ""{ExpectedDirectoryName}"" ""{ActualDirectoryName}""");
146+
private void EnsureTestContextDump() => AddTestRunFile("TestContext.json", JsonConvert.SerializeObject(this._testContext, new JsonSerializerSettings
147+
{
148+
Formatting = Formatting.Indented,
149+
ContractResolver = new TestContextContractResolver()
150+
}));
151+
152+
private void AddTestRunFile(string fileName, string content)
140153
{
141-
const string fileName = "winmerge.bat";
142154
string path = Path.Combine(this.RunDirectory, fileName);
143155

144156
if (!this.ShouldRegisterTestRunFile(path))
145157
return;
146158

147-
WriteContentToFile(path, $@"@echo off
148-
start winmergeU ""{ExpectedDirectoryName}"" ""{ActualDirectoryName}""");
159+
WriteContentToFile(path, content);
149160
this.RegisterFile(path, scopeIsTestRun: true);
150161
}
151162

@@ -225,5 +236,19 @@ public enum EventLogEntryType
225236
SuccessAudit = 8,
226237
FailureAudit = 16
227238
}
239+
240+
private sealed class TestContextContractResolver : DefaultContractResolver, IContractResolver
241+
{
242+
protected override JsonObjectContract CreateObjectContract(Type objectType)
243+
{
244+
JsonObjectContract contract = base.CreateObjectContract(objectType);
245+
if (objectType.FullName == "Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.TestContextImplementation")
246+
{
247+
// Self referencing loop detected for property 'Context' with type 'Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.TestContextImplementation'. Path ''.
248+
contract.Properties.Remove("Context");
249+
}
250+
return contract;
251+
}
252+
}
228253
}
229254
}

0 commit comments

Comments
 (0)