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.

Class Cleanup gets called immediately after a single test case using VSTestConsoleWrapper

See original GitHub issue

Describe the bug

I am using VsTestConsoleWrapper api to run tests. I have added same test method twice using below code -

Collection<TestCase> cases = new Collection<TestCase>();
  cases.Add(testCase);
  cases.Add(testCase);
var  consoleWrapper = new VsTestConsoleWrapper(runnerLocation, new ConsoleParameters { LogFilePath = logFilePath });
consoleWrapper.RunTests(cases, defaultRunSettings, handler);

However the ClassCleanup method gets called immediately after the first time test method is called and does not wait for the second instance to finish. Is this expected?

Expected behavior

class initialize  started at 3/9/2023 7:19:28 PM
test initialize  started at 3/9/2023 7:19:28 PM
TestA started at 3/9/2023 7:19:28 PM
TestA ended at 3/9/2023 7:20:18 PM
test cleanup  started at 3/9/2023 7:20:18 PM
class cleanup  started at 3/9/2023 **7:21:09** PM
test initialize  started at 3/9/2023 7:20:19 PM
TestA started at 3/9/2023 7:20:19 PM
TestA ended at 3/9/2023 7:21:09 PM
test cleanup  started at 3/9/2023 7:21:09 PM

Actual behavior

Logs from Test Run

test initialize  started at 3/9/2023 7:19:28 PM
TestA started at 3/9/2023 7:19:28 PM
TestA ended at 3/9/2023 7:20:18 PM
test cleanup  started at 3/9/2023 7:20:18 PM
class cleanup  started at 3/9/2023 7:20:19 PM
test initialize  started at 3/9/2023 7:20:19 PM
TestA started at 3/9/2023 7:20:19 PM
TestA ended at 3/9/2023 7:21:09 PM
test cleanup  started at 3/9/2023 7:21:09 PM

Additional context

Note how Class Cleanup was called at 7.20.19 before second run of TestA finished (7.21.09). Shouldn’t it be called after 7.21.09?

Issue Analytics

  • State:open
  • Created 6 months ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
agadekarcommented, Mar 13, 2023

can we please add it as a feature to recognize duplicate test cases in a single run as individual test cases and run class cleanup only after all these test cases have finished running?

0reactions
engyebrahimcommented, Mar 13, 2023

Thanks @agadekar,

in here the problem when happens when we run the same test twice from a class has only one test and that’s because in the code we check if all tests run then call the class cleanup which happens after first call to the test.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to run ClassCleanup (MSTest) after each class with ...
Each test class starts from ClassInitialize and finishes by ClassCleanup. My problem is that ClassCleanup isn't called at the end of each class, ......
Read more >
Testing in Go: Clean Tests Using t.Cleanup - Ilija Eftimov ‍
Cleanup registers a function to be called when the test and all its subtests complete. This means that even if our tests run...
Read more >
Demystifying useEffect's clean-up function
useEffect's clean-up function can be pretty confusing, especially if you're still trying to think in lifecycle methods. Let's clarify the clean-up function ...
Read more >
Understanding React's useEffect cleanup function
Learn React's useEffect cleanup function to prevent unwanted application behaviors like memory leaks by cleaning up effects.
Read more >
The useEffect cleanup and the two circumstances it's called.
The cleanup function is a function returned from within the effect function. It gets called when the component unmounts but you probably ...
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