Last active
August 4, 2025 14:40
-
-
Save poizan42/f0645f3a7f46019d8c159a693125b769 to your computer and use it in GitHub Desktop.
MSTest project demonstrating AddResultFile not working with long filenames
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /.vs | |
| /bin | |
| /obj | |
| /TestResults |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8" ?> | |
| <RunSettings> | |
| <MSTest> | |
| <DeleteDeploymentDirectoryAfterTestRunIsComplete>False</DeleteDeploymentDirectoryAfterTestRunIsComplete> | |
| </MSTest> | |
| </RunSettings> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| | |
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [assembly: Parallelize(Scope = ExecutionScope.ClassLevel)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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