Closed
Description
Describe the bug
When using Datarows and ResultFiles together, the ResultFiles of every datarow are attached to all other datarows too, not just the current one.
Steps To Reproduce
- Checkout this repo https://github.com/baumheld/mstest_multiple_ResultFiles/
- Execute
RunTests.ps1
in Powershell (Right-click it).
This will run a single test with 5 datarows. (see below)
Each datarow will attach oneResultFile
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace TestProject;
[TestClass]
public class TestClass
{
public TestContext TestContext { get; set; }
[TestMethod]
[DataRow("DataRow1")]
[DataRow("DataRow2")]
[DataRow("DataRow3")]
[DataRow("DataRow4")]
[DataRow("DataRow5")]
public void TestMethodAsync(string datarowName)
{
TestContext.AddResultFile(datarowName);
}
}
- Open newly created TRX file under
..\tests\logs\
with an editor.
Each test (one test for each datarow) now contains 5 resultfiles.
Not only does one test contain their own ResultFile, but also all ResultFiles of the other datarows.
Expected behavior
[...]
<UnitTestResult testName="TestMethodAsync (DataRow1)" >
<ResultFiles>
<ResultFile path="T:\src\mstest_multiple_ResultFiles\bin\Debug\net8.0\DataRow1" />
</ResultFiles>
</UnitTestResult>
<UnitTestResult testName="TestMethodAsync (DataRow2)" >
<ResultFiles>
<ResultFile path="T:\src\mstest_multiple_ResultFiles\bin\Debug\net8.0\DataRow2" />
</ResultFiles>
</UnitTestResult>
[...]
Actual behavior
[...]
<UnitTestResult testName="TestMethodAsync (DataRow1)" >
<ResultFiles>
<ResultFile path="T:\src\mstest_multiple_ResultFiles\bin\Debug\net8.0\DataRow1" />
<ResultFile path="T:\src\mstest_multiple_ResultFiles\bin\Debug\net8.0\DataRow2" />
<ResultFile path="T:\src\mstest_multiple_ResultFiles\bin\Debug\net8.0\DataRow3" />
<ResultFile path="T:\src\mstest_multiple_ResultFiles\bin\Debug\net8.0\DataRow4" />
<ResultFile path="T:\src\mstest_multiple_ResultFiles\bin\Debug\net8.0\DataRow5" />
</ResultFiles>
</UnitTestResult>
<UnitTestResult testName="TestMethodAsync (DataRow2)" >
<ResultFiles>
<ResultFile path="T:\src\mstest_multiple_ResultFiles\bin\Debug\net8.0\DataRow1" />
<ResultFile path="T:\src\mstest_multiple_ResultFiles\bin\Debug\net8.0\DataRow2" />
<ResultFile path="T:\src\mstest_multiple_ResultFiles\bin\Debug\net8.0\DataRow3" />
<ResultFile path="T:\src\mstest_multiple_ResultFiles\bin\Debug\net8.0\DataRow4" />
<ResultFile path="T:\src\mstest_multiple_ResultFiles\bin\Debug\net8.0\DataRow5" />
</ResultFiles>
</UnitTestResult>
[...]
Additional context
I'm quite sure this bug was introduced with the MSTest SDK.
I have older .trx-files generated with MSTest meta nuget package, which have just one ResultFile
per datarow.