Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8515311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:06:47+00:00 2026-06-11T05:06:47+00:00

I’m trying to setup my tests using Xunit. I have a requirement to delete

  • 0

I’m trying to setup my tests using Xunit. I have a requirement to delete all images in a folder start of the tests, and then each method does some image resizing and saves a copy of it’s output to the folder. The folder should only be emptied once, and then each method will save their own image into the folder.

When I use IUseFixture<T>, the ClearVisualTestResultFolder function is still being called before every test, so I only end up with one image in the folder.

public class Fixture
{
    public void Setup()
    {
        ImageHelperTest.ClearVisualTestResultFolder();
    }
}

public class ImageHelperTest : IUseFixture<EngDev.Test.Fixture>
{
    public void SetFixture(EngDev.Test.Fixture data)
    {
        data.Setup();
    }

    public static void ClearVisualTestResultFolder()
    {
        // Logic to clear folder
    }
}

If I put the ClearVisualTestResultFolder in the constructor, it is also being called once for every test method. I need this just run once before all test methods are executed, how can I achieve this?

If it matters, I use the ReSharper test runner.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:06:48+00:00Added an answer on June 11, 2026 at 5:06 am

    Following the guidance in this xUnit discussion topic, it looks like you need to implement a constructor on the Fixture and also implement IDisposable. Here’s a complete sample that behaves the way you want:

    using System;
    using System.Diagnostics;
    using Xunit;
    using Xunit.Sdk;
    
    namespace xUnitSample
    {
        public class SomeFixture : IDisposable
        {
            public SomeFixture()
            {
                Console.WriteLine("SomeFixture ctor: This should only be run once");
            }
    
            public void SomeMethod()
            {
                Console.WriteLine("SomeFixture::SomeMethod()");
            }
    
            public void Dispose()
            {
                Console.WriteLine("SomeFixture: Disposing SomeFixture");
            }
        }
    
        public class TestSample : IUseFixture<SomeFixture>, IDisposable
        {
            public void SetFixture(SomeFixture data)
            {
                Console.WriteLine("TestSample::SetFixture(): Calling SomeMethod");
                data.SomeMethod();
            }
    
            public TestSample()
            {
                Console.WriteLine("This should be run once before every test " + DateTime.Now.Ticks);
            }
    
            [Fact]
            public void Test1()
            {
                Console.WriteLine("This is test one.");
            }
    
            [Fact]
            public void Test2()
            {
                Console.WriteLine("This is test two.");
            }
    
            public void Dispose()
            {
                Console.WriteLine("Disposing");
            }
        }
    }
    

    When running this from the console runner, you’ll see the following output:

    D:\xUnit>xunit.console.clr4.exe test.dll /html foo.htm xUnit.net
    console test runner (64-bit .NET 4.0.30319.17929) Copyright (C)
    2007-11 Microsoft Corporation.

    xunit.dll: Version 1.9.1.1600 Test assembly: test.dll

    SomeFixture ctor: This should only be run once

    Tests complete: 2 of 2

    SomeFixture: Disposing SomeFixture

    2 total, 0 failed, 0 skipped, took 0.686 seconds

    Then, when you crack open the test output file foo.htm, you’ll see the other test output.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Basically, what I'm trying to create is a page of div tags, each has
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.