locked
[VSTest] How to handle test start event? RRS feed

  • Question

  • Hi! I want to get and handle test start event. When method started and hasn't finished. I created my custom SimpleLogger.

    [ExtensionUri("logger://SimpleLogger")]
    	[FriendlyName("SimpleLogger")]
    	public sealed class SimpleLogger : ITestLogger
    	{
    		public void Initialize(TestLoggerEvents events, string testRunDirectory)
    		{
    			events.TestRunMessage += TestRunMessageHandler;
    			events.TestResult += TestResultHandler; 
    			events.TestRunComplete += TestRunCompleteHandler; 
    			events.TestRunStart += TestRunStartHandler;
    			events.DiscoveredTests += DiscoveredTestsHandler;
    			events.DiscoveryMessage += DiscoveryMessageHandler;
    			events.DiscoveryComplete += DiscoveryCompleteHandler;
    			events.DiscoveryStart += DiscoveryStart;
    
    		}
    
    		/// <summary>
    		/// Called when a test run starts.
    		/// </summary>
    		private void TestRunStartHandler(object sender, TestRunStartEventArgs e)
    		{
    			// Called only once before all tests.
    			Console.WriteLine("TestRunStartHandler");
    		}
    
    		/// <summary>
    		/// Called when discovered tests are received.
    		/// </summary>
    		private void DiscoveredTestsHandler(object sender, DiscoveredTestsEventArgs e)
    		{
    			// Never called.
    			Console.WriteLine("DiscoveredTests");
    		}
    
    		/// <summary>
    		/// Called when a discovery message is received.
    		/// </summary>
    		private void DiscoveryMessageHandler(object sender, TestRunMessageEventArgs e)
    		{
    			// Never called.
    			Console.WriteLine("DiscoveryMessage");
    		}
    
    		/// <summary>
    		/// Called when test discovery is complete.
    		/// </summary>
    		private void DiscoveryCompleteHandler(object sender, DiscoveryCompleteEventArgs e)
    		{
    			// Never called.
    			Console.WriteLine("DiscoveryComplete");
    		}
    
    		/// <summary>
    		/// Called when test discovery starts.
    		/// </summary>
    		private void DiscoveryStart(object sender, DiscoveryStartEventArgs e)
    		{
    			// Never called.
    			Console.WriteLine("DiscoveryStart");
    		}
    
    		/// <summary>
    		/// Called when a test message is received.
    		/// </summary>
    		private void TestRunMessageHandler(object sender, TestRunMessageEventArgs e)
    		{
    			// Never called.
    			Console.WriteLine("TestRunMessage");
    		}
    
    		/// <summary>
    		/// Called when a test result is received.
    		/// </summary>
    		private void TestResultHandler(object sender, TestResultEventArgs e)
    		{
    			// Called after each test.
    			Console.WriteLine("TestResult");
    		}
    
    		/// <summary>
    		/// Called when a test run is completed.
    		/// </summary>
    		private void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e)
    		{
    			// Called once after all tests.
    			Console.WriteLine("TestRunComplete");
    		}
    	}

    How can I handle the start each test event? I need know when each test starts. 
    Monday, April 2, 2018 7:56 AM

All replies

  • Hi friend, 

    Found this similar thread and the answer from Tim might help: 

    https://stackoverflow.com/a/2697721/9125096

    which is an implementation of event monitor. 

     

    Regards, 

    Fletcher 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Fletch Zhou Tuesday, April 3, 2018 10:11 AM
    Tuesday, April 3, 2018 10:11 AM