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 1049223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:34:54+00:00 2026-05-16T16:34:54+00:00

I’d like to get the currently executing NUnit test in a helper method I’m

  • 0

I’d like to get the currently executing NUnit test in a helper method I’m using. We’re actually using NUnit for integration tests here — not unit tests. When a test finishes, we’d like to have the test clean up some log files when it’s done. Currently, I’ve hacked around this using the StackFrame class:

class TestHelper
{
    string CurrentTestFixture;
    string CurrentTest;
    public TestHelper()
    {
        var callingFrame = new StackFrame(1);
        var method = callingFrame.GetMethod();
        CurrentTest = method.Name;
        var type = method.DeclaringType;
        CurrentTestFixture = type.Name;
    }
    public void HelperMethod()
    {
        var relativePath = Path.Combine(CurrentTestFixture, CurrentTest);
        Directory.Delete(Path.Combine(Configurator.LogPath, relativePath));
    }
}

[TestFixture]
class Fix
{
    [Test]
    public void MyTest()
    {
        var helper = new TestHelper();
        //Do other testing stuff
        helper.HelperMethod();
    }
    [Test]
    public void MyTest2()
    {
        var helper = new TestHelper();
        //Do some more testing stuff
        helper.HelperMethod();
    }
}

This works just fine, except there are cases where I’d like to make the TestHelper class part of my fixture, like this:

[TestFixture]
class Fix
{
    private TestHelper helper;

    [Setup]
    public void Setup()
    {
        helper = new TestHelper();
    }

    [TearDown]
    public void TearDown()
    {
        helper.HelperMethod();
    }

    [Test]
    public void MyTest()
    {
        //Do other testing stuff
    }
    [Test]
    public void MyTest2()
    {
        //Do some more testing stuff
    }
}

I can’t simply make this class into a global fixture because sometimes a single test will use it more than once, and sometimes a test need not use it at all. Sometimes a test needs to attach specific properties to the TestHelper…. things like that.

As a result, I’d like to be able to somehow get the currently executing test without having to manually repeat the name of the fixture and test in the several thousand test cases I’m looking at.

Is there a way to get such information?

  • 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-05-16T16:34:55+00:00Added an answer on May 16, 2026 at 4:34 pm

    NUnit 2.5.7 has added an “experimental” TestContext class. One of the properties it contains is TestName. I haven’t tried it, so I don’t know whether the info is available in the TearDown method.

    • 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’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I would like to count the length of a string with PHP. The string
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
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported

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.