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.

AssemblyInitialize/Cleanup should not be executed when all tests are ignored

See original GitHub issue

Describe the bug

When all tests in the project are ignored, the AssemblyInitialize method is not executed. The AssemblyCleanup is always executed. I’d expect both methods to always execute or not execute. The answer to this issue suggests the AssemblyCleanup will always execute, so I expect the same from AssemblyInitialize (otherwise, what the cleanup method supposed to clean?)

Steps To Reproduce

Set the breakpoint in AssemblyInitialize and AssemblyCleanup and debug

[TestClass]
public class UnitTest1
{
    [AssemblyInitialize]
    public static void AssemblyInitialize(TestContext context)
    {
    }

    [AssemblyCleanup]
    public static void AssemblyCleanup()
    {
    }

    [TestMethod, Ignore]
    public void TestMethod1()
    {
    }
}

Expected behavior

Both AssemblyInitialize and AssemblyCleanup are executed

Actual behavior

Only AssemblyCleanup is executed

AB#1850400

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
gao-arturcommented, Jul 11, 2023

Skipping both is even better. I see no point in initializing something that won’t be used, especially if it’s a heavy operation like creating and initializing DB, for example.

1reaction
engyebrahimcommented, May 19, 2023

@Evangelink I can repro in these versions 2.2.10, 2.2.8, 2.2.4.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - AssemblyCleanup Not being run.
If a [TestClass] inherits from a base class that is in a different assembly of the derived class, the base class [AssemblyInitialize] and...
Read more >
Run VSTest tests in parallel - Azure Pipelines
This option should be used when tests within an assembly have dependencies or utilize AssemblyInitialize and AssemblyCleanup , or ...
Read more >
Full MSTest support for VS9/VS8 : RSRP-272588 - YouTrack
1) The test run config file is either being ignored or the Deployment section is being ignored. ... You don't seem to support...
Read more >
How To Write Automated Tests Using MsTest Framework? ...
[AssemblyInitialize] – Method with this attribute will be executed only once before executing all the tests in the whole test repo; [ ...
Read more >
NUnit vs. XUnit vs. MSTest: Comparing Unit Testing ...
[Ignore], Marks a test method or test class that should not be ... execution of any tests in Test Assembly, N.A, [AssemblyInitialize], N.A....
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