Describe the issue you've observed
I have a test:
[TestMethod]
[TestCategory("VisualParity")]
[DataTestMethod]
[DataRow(TestScreen.Large, LocaleDirection.RTL, Ring.WorldWide)]
public void HomeConsumer_Hero_Screenshot(int screenWidth, string direction, string ring)
{
SetupTest(screenWidth, direction, ring);
// in some later code, where TestContext is passed in...
var screenshotName = TestContext.TestName + "_" + TestContext.DataRow.ItemArray[0];
// ...
}
DataRow is null
What steps can reproduce the defect?
Please share the setup, sample project, target platform (desktop, core, uap)
Nothing special besides above test. It is a desktop net45 project
Share the expected output
I would expect TestContext.DataRow to be properly populated
What is the behavior observed?
TestContext.DataRow is null
Please share additional details about the test environment.
Operating system, Build version of vstest.console, Package version of MSTest
framework and adapter
VS2017 15.4
Windows 10 Latest
MSTest 1.1.18
@josephliccini : This is By-Design. All data driven tests based off of the new ITestDataSource contract (DataRow included) provide values via method arguments. The TestContext.DataRow values will only be filled in when a DataSource attribute is used. Here is the documentation of the design and usage.
@AbhitejJohn Thanks!! We are really enjoying the new features, especially data driven test. Will hook this up!!
Just double checking, this document is saying, if you need DataRow access, then you would have to access the entries via the parameters of the [TestMethod]. There is no way to get the parameters via the test context?
Not an issue, and I think the design is sound, just trying to make sure I understand.
Thanks!
That is correct. Testcontext would not have these filled in anymore for ITestDataSource extensions.
@AbhitejJohn , is there any other way/workaround to get the data other than from Testmethod parameters when I am using DataRow, I am asking is because my test framework is using [TestCleanup] method to generate test report via reading TestContext to get test name, status etc. And now the datarow in TestContext is null by design if using [DataRow]
can this be re-opened. it would be really helpful to get access to the test parameters via the TestContext
Most helpful comment
can this be re-opened. it would be really helpful to get access to the test parameters via the TestContext