1
votes

I have a data driven CodedUI test method named myTestMethod, which uses XML for supplying input data.

For each run on a data set, CodedUI reports something like this in the Test Explorer:

Test Passed - myTestMethod (Data Row 0)
Test Passed - myTestMethod (Data Row 1)
Test Failed - myTestMethod (Data Row 2) <error details>
Test Failed - myTestMethod (Data Row 3) <error details>

I was wondering is there is a way to set the test name to something more identifiable (probably from the input data set itself).

Seems like CodedUI uses TestContext.TestName for this reporting purpose, but, it is a readonly property. Is there a way to set it somewhere else, somehow?

Please help. Thanks, Harit

3

3 Answers

1
votes

Ok i understand you now. I actually have a class where i write general functions. One of them is for save the test results as i want.

I use data driven based in XML. then my Employe1 and Employe2 are different runs of the same test_method.

Just locate [TestCleanup()] and call here a function to save a log has you need.

Log can be saved in csv format, plain text separated by ; for example with StreamWriter.

namespace NAME_SPACE
{

[CodedUITest]
public class Program_Something_BlaBla
{
    Stopwatch stopWatch = new Stopwatch();

    [TestMethod(), Timeout(999999999)]
    [DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", PATH_XML, "DATOS", DataAccessMethod.Sequential)]


    public void Program_Something_BlaBla_Method()
    {

    string employe = TestContext.DataRow["EMPLOYE"].ToString();

        try
        {
           //Test actions
           ...

        {
        catch (Exception g)
        {
            ...
           return;

        }
    }

    #region Additional test attributes
    // You can use the following additional attributes as you write your tests:

    ////Use TestInitialize to run code before running each test 
    [TestInitialize()]
    public void MyTestInitialize()
    {
        stopWatch.Start();
           ...
    }

    //Use TestCleanup to run code after each test has run
    [TestCleanup()]
    public void MyTestCleanup()
    {
        stopWatch.Stop();
        ...
        Common.EndTest(employe);

    }

    #endregion

Hope it helps,

0
votes

I don't want to say it's impossible, but the Test Explorer in populated at compile time and the data would be pulled in at run time.

0
votes

I don't think this would be possible. The only way for you is to read the generated "TRX" file ( as it is xml) and replace the values by reading your csvs. Might need to do a tool but the overhead is huge.