TestCaseStartEventArgs doesn't return current test case being executed
-
jeudi 15 mars 2012 11:14
As mentioned in one of the post, i was using the following code, to capture Test Case ID that's current being run in the MTM.
using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.Execution;
using Microsoft.VisualStudio.TestTools.Common;using Microsoft.TeamFoundation.TestManagement.Client;
using Microsoft.TeamFoundation.TestManagement.Common;
using System.Xml;
using System.IO;namespace TestCaseCollector
{
[DataCollectorTypeUri("datacollector://Microsoft/PSRDataCollector/1.0")]
[DataCollectorFriendlyName("Test Case Capture")]
public class TestCaseIDCollector : DataCollector
{private DataCollectionEvents dataEvents;
private DataCollectionLogger dataLogger;
private DataCollectionSink dataSink;
private XmlElement configurationSettings;public override void Initialize(XmlElement configurationElement, DataCollectionEvents events, DataCollectionSink sink,
DataCollectionLogger logger, DataCollectionEnvironmentContext environmentContext)
{
dataEvents = events; // The test events
//int iTestRunID = environmentContext.TcmContext.TestRunId;
dataLogger = logger; // The error and warning log
dataSink = sink; // Saves collected data
// Configuration from the test settings
configurationSettings = configurationElement;
File.Delete(@"C:\VSRunnerAutomationID.txt");
dataEvents.TestCaseStart += new EventHandler<TestCaseStartEventArgs>(OnTestCaseStart);
int iRun = environmentContext.TcmContext.TestRunId;
//ITestRun sRun =
}
private void OnTestCaseStart(object sender, TestCaseStartEventArgs e)
{
try
{
File.WriteAllText(@"C:\VSRunnerAutomationID.txt", e.TcmInformation.TestCaseId.ToString());
}
catch(Exception e1)
{
File.WriteAllText(@"C:\VSRunnerAutomationID.txt", "no_tfs_execution");
}
}
}}
I'm using this data collector in my test & when i execute automated Test cases from MTM, I get Test Case ID being executed currently & based on that Test Case ID, i perform appropriate coding.The problem is that the line e.TcmInformation.TestCaseId.ToString() always returns the first test case in the run & it doesn't return the next test case when OnTestCaseStart is called for the next time. I verified that OnTestCaseStart is called whenever test case run starts in a test suite, but it doesn't return the latest values but always return the first Test Case ID in the Suite Run.
How to get next TestCase ID in the suite Run? Is it an issue with TestCaseStartEventArgs or something missing in the above code?
Appreciate your help as i'm struct at this place to complete one of the automation project.
Thanks,
J V Rao
Toutes les réponses
-
jeudi 15 mars 2012 08:57
As mentioned in one of the post, i was using the following code, to capture Test Case ID that's current being run in the MTM.
using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.Execution;
using Microsoft.VisualStudio.TestTools.Common;using Microsoft.TeamFoundation.TestManagement.Client;
using Microsoft.TeamFoundation.TestManagement.Common;
using System.Xml;
using System.IO;namespace TestCaseCollector
{
[DataCollectorTypeUri("datacollector://Microsoft/PSRDataCollector/1.0")]
[DataCollectorFriendlyName("Test Case Capture")]
public class TestCaseIDCollector : DataCollector
{private DataCollectionEvents dataEvents;
private DataCollectionLogger dataLogger;
private DataCollectionSink dataSink;
private XmlElement configurationSettings;public override void Initialize(XmlElement configurationElement, DataCollectionEvents events, DataCollectionSink sink,
DataCollectionLogger logger, DataCollectionEnvironmentContext environmentContext)
{
dataEvents = events; // The test events
//int iTestRunID = environmentContext.TcmContext.TestRunId;
dataLogger = logger; // The error and warning log
dataSink = sink; // Saves collected data
// Configuration from the test settings
configurationSettings = configurationElement;
File.Delete(@"C:\VSRunnerAutomationID.txt");
dataEvents.TestCaseStart += new EventHandler<TestCaseStartEventArgs>(OnTestCaseStart);
int iRun = environmentContext.TcmContext.TestRunId;
//ITestRun sRun =
}
private void OnTestCaseStart(object sender, TestCaseStartEventArgs e)
{
try
{
File.WriteAllText(@"C:\VSRunnerAutomationID.txt", e.TcmInformation.TestCaseId.ToString());
}
catch(Exception e1)
{
File.WriteAllText(@"C:\VSRunnerAutomationID.txt", "no_tfs_execution");
}
}
}}
I'm using this data collector in my test & when i execute automated Test cases from MTM, I get Test Case ID being executed currently & based on that Test Case ID, i perform appropriate coding.
The problem is that the line e.TcmInformation.TestCaseId.ToString() always returns the first test case in the run & it doesn't return the next test case when OnTestCaseStart is called for the next time. I verified that OnTestCaseStart is called whenever test case run starts in a test suite, but it doesn't return the latest values but always return the first Test Case ID in the Suite Run.
How to get next TestCase ID in the suite Run? Is it an issue with TestCaseStartEventArgs or something missing in the above code?
Appreciate your help as i'm struct at this place to complete one of the automation project.
Thanks,
J V Rao
- Fusionné Forrest GuoMicrosoft Employee, Moderator dimanche 18 mars 2012 13:20 duplicate thread, focus on one thread
-
jeudi 15 mars 2012 11:17
As mentioned in one of the post, i was using the following code, to capture Test Case ID that's current being run in the MTM.
using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.Execution;
using Microsoft.VisualStudio.TestTools.Common;using Microsoft.TeamFoundation.TestManagement.Client;
using Microsoft.TeamFoundation.TestManagement.Common;
using System.Xml;
using System.IO;namespace TestCaseCollector
{
[DataCollectorTypeUri("datacollector://Microsoft/PSRDataCollector/1.0")]
[DataCollectorFriendlyName("Test Case Capture")]
public class TestCaseIDCollector : DataCollector
{private DataCollectionEvents dataEvents;
private DataCollectionLogger dataLogger;
private DataCollectionSink dataSink;
private XmlElement configurationSettings;public override void Initialize(XmlElement configurationElement, DataCollectionEvents events, DataCollectionSink sink,
DataCollectionLogger logger, DataCollectionEnvironmentContext environmentContext)
{
dataEvents = events; // The test events
//int iTestRunID = environmentContext.TcmContext.TestRunId;
dataLogger = logger; // The error and warning log
dataSink = sink; // Saves collected data
// Configuration from the test settings
configurationSettings = configurationElement;
File.Delete(@"C:\VSRunnerAutomationID.txt");
dataEvents.TestCaseStart += new EventHandler<TestCaseStartEventArgs>(OnTestCaseStart);
int iRun = environmentContext.TcmContext.TestRunId;
//ITestRun sRun =
}
private void OnTestCaseStart(object sender, TestCaseStartEventArgs e)
{
try
{
File.WriteAllText(@"C:\VSRunnerAutomationID.txt", e.TcmInformation.TestCaseId.ToString());
}
catch(Exception e1)
{
File.WriteAllText(@"C:\VSRunnerAutomationID.txt", "no_tfs_execution");
}
}
}}
I'm using this data collector in my test & when i execute automated Test cases from MTM, I get Test Case ID being executed currently & based on that Test Case ID, i perform appropriate coding.The problem is that the line e.TcmInformation.TestCaseId.ToString() always returns the first test case in the run & it doesn't return the next test case when OnTestCaseStart is called for the next time. I verified that OnTestCaseStart is called whenever test case run starts in a test suite, but it doesn't return the latest values but always return the first Test Case ID in the Suite Run.
How to get next TestCase ID in the suite Run? Is it an issue with TestCaseStartEventArgs or something missing in the above code?
Appreciate your help as i'm struct at this place to complete one of the automation project.
Thanks,
J V Rao
- Fusionné Tony xiaoModerator vendredi 16 mars 2012 06:28 duplicate
-
vendredi 16 mars 2012 08:26Modérateur
Hello J V Rao,
I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.
Thanks.
Vicky Song [MSFT]
MSDN Community Support | Feedback to us
-
mardi 20 mars 2012 19:58Propriétaire
Assuming that the question here is to have an ability to find out associated test case id in test context (or anywhere else during test execution), then, the answer is that it is a limitation of the current product - it cannot be done now. If you would like to suggest this for a future version please visit http://visualstudio.uservoice.com/forums/121579-visual-studio and submit it there.Trevor Hancock (Microsoft)
Please remember to "Mark As Answer" the replies that help.- Proposé comme réponse Trevor HancockMicrosoft Employee, Moderator vendredi 23 mars 2012 17:31
- Marqué comme réponse Trevor HancockMicrosoft Employee, Moderator mercredi 28 mars 2012 21:42
-
jeudi 19 avril 2012 11:14
Hi,
I faced the same problem earlier
My agent was 2010 and the controller was 2010 SP1.
Please update both your agent machine and controller machine to VS 2010 SP1. It will work then :)
- Proposé comme réponse Idries jeudi 26 juillet 2012 07:17
-
jeudi 26 juillet 2012 07:17Thats it! Thank you very much!

