question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Timeout attribute does not call test cleanup method

See original GitHub issue

Steps to reproduce

[TestClass] 
public class TestCleanup 
{ 
[TestInitialize()] 
public void MyTestInitialize() 
{ 
Console.WriteLine("Calling initialize"); 
} 


// Use TestCleanup to run code after each test has run 

[TestCleanup()] 
public void MyTestCleanup() 
{ 
MessageBox.Show("Cleanup"); 
Console.WriteLine( ng cleanup"); 
} 

[Timeout(5000)] 
[TestMethod] 
public void TestMethod1() 
{ 
Console.WriteLine("Sleeping for 10 seconds"); 
System.Threading.Thread.Sleep(10000); 
Console.WriteLine("Waking up"); 
} 

} 

Expected behavior

It is essential all tests execute their TestCleanup code, as this code may have important steps to recover from an error such as a time out.

Actual behavior

The result of executing this code is the test times out but the message box is not displayed and the Calling cleanup message is not written to the console.

AB#1634637

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:34
  • Comments:18 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
kzucommented, Nov 21, 2019

I can’t fathom how this is remotely an enhancement rather than a serious bug that should be fixed ASAP 😕. Makes using Timeout absolutely useless and dangerous.

2reactions
dbtfsbrecommented, Sep 23, 2019

In more complex scenarios like E2E UI tests where more than one failure may need to be collected and analyzed per test, this could be called a bug rather than enhancement.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Timeout attribute for Mstest does not call test cleanup method
I consider this a bug. It is essential all tests execute their TestCleanup code, as this code may have important steps to recover...
Read more >
MStest aborts test cleanup - visual studio 2013
The issue is that when a test is aborted with timeout, the test cleanup is given a very short amount of time to...
Read more >
Timeout
The TimeoutAttribute is used to specify a timeout value in milliseconds for a test case. If the test case runs longer than the...
Read more >
Most Complete NUnit Unit Testing Framework Cheat Sheet
The TimeoutAttribute is used to specify a timeout value in milliseconds for a test case. If the test case runs longer than the...
Read more >
Writing tests for Twisted code using Trial
The way to do this in Trial is to set the .timeout attribute on your unit test method. Set the attribute to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found