TestCaseStartEventArgs doesn't return current test case being executed
-
15 มีนาคม 2555 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
ตอบทั้งหมด
-
15 มีนาคม 2555 8: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
- รวมโดย Forrest GuoModerator 18 มีนาคม 2555 13:20 duplicate thread, focus on one thread
-
15 มีนาคม 2555 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
- รวมโดย Tony xiaoModerator 16 มีนาคม 2555 6:28 duplicate
-
16 มีนาคม 2555 8:26ผู้ดูแล
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
-
20 มีนาคม 2555 19:58เจ้าของ
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.- เสนอเป็นคำตอบโดย Trevor HancockMicrosoft, Moderator 23 มีนาคม 2555 17:31
- ทำเครื่องหมายเป็นคำตอบโดย Trevor HancockMicrosoft, Moderator 28 มีนาคม 2555 21:42
-
19 เมษายน 2555 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 :)
- เสนอเป็นคำตอบโดย Idries 26 กรกฎาคม 2555 7:17
-
26 กรกฎาคม 2555 7:17Thats it! Thank you very much!