Skip to content

Instantly share code, notes, and snippets.

@poizan42
Last active August 4, 2025 14:40
Show Gist options
  • Select an option

  • Save poizan42/f0645f3a7f46019d8c159a693125b769 to your computer and use it in GitHub Desktop.

Select an option

Save poizan42/f0645f3a7f46019d8c159a693125b769 to your computer and use it in GitHub Desktop.
MSTest project demonstrating AddResultFile not working with long filenames
/.vs
/bin
/obj
/TestResults
<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
<MSTest>
<DeleteDeploymentDirectoryAfterTestRunIsComplete>False</DeleteDeploymentDirectoryAfterTestRunIsComplete>
</MSTest>
</RunSettings>
<Project Sdk="MSTest.Sdk/3.9.3">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<!--
Displays error on console in addition to the log file. Note that this feature comes with a performance impact.
For more information, visit https://learn.microsoft.com/dotnet/core/testing/unit-testing-platform-integration-dotnet-test#show-failure-per-test
-->
<TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>
<RunSettingsFilePath>$(MSBuildProjectDirectory)\.runsettings</RunSettingsFilePath>
</PropertyGroup>
</Project>

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36327.8 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddResultFileTest", "AddResultFileTest.csproj", "{56F69267-3413-4BDA-95D1-8015C9C885FF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{56F69267-3413-4BDA-95D1-8015C9C885FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{56F69267-3413-4BDA-95D1-8015C9C885FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{56F69267-3413-4BDA-95D1-8015C9C885FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{56F69267-3413-4BDA-95D1-8015C9C885FF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BE7DA027-F103-407C-AE27-C92C34A03668}
EndGlobalSection
EndGlobal
[assembly: Parallelize(Scope = ExecutionScope.ClassLevel)]
namespace AddResultFileTest;
[TestClass]
public sealed class TestResultTests
{
public TestContext TestContext { get; set; }
[TestMethod]
public void AddResultFileInTestResultsDirectory()
{
string filePath = Path.Combine(TestContext.TestResultsDirectory!, "ResultFile.txt");
File.WriteAllText(filePath, "Hello, World!");
TestContext.AddResultFile(filePath);
}
[TestMethod]
public void AddLongFilenameResultFileInTestResultsDirectory()
{
string fileDir = Path.Combine(TestContext.TestResultsDirectory!, new string('X', 250));
Directory.CreateDirectory(fileDir);
string filePath = Path.Combine(fileDir, "ResultFile.txt");
File.WriteAllText(filePath, "Hello, World!");
TestContext.AddResultFile(filePath);
}
[TestMethod]
public void AddResultFileInTempDirectory()
{
string filePath = Path.GetTempFileName();
File.WriteAllText(filePath, "Hello, World!");
TestContext.AddResultFile(filePath);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment