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

  • Home
  • SEARCH
  • 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 8370561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:56:33+00:00 2026-06-09T13:56:33+00:00

I store various information about a given test (IDs for multiple bug tracking systems)

  • 0

I store various information about a given test (IDs for multiple bug tracking systems) in an attribute like so:

[TestCaseVersion("001","B-8345","X543")]
public void TestSomethingOrOther()

In order to fetch this information during the course of a test, I wrote the below code:

     public string GetTestID()
     {
        StackTrace st = new StackTrace(1);
        StackFrame sf;
        for (int i = 1; i <= st.FrameCount; i++)
        {
            sf = st.GetFrame(i);
            if (null == sf) continue;
            MethodBase method = sf.GetMethod();
            if (method.GetCustomAttributes(typeof(TestAttribute), true).Length == 1)
            {
                if (method.GetCustomAttributes(typeof(TestCaseVersion), true).Length == 1)
                {
                    TestCaseVersion tcv =
                        sf.GetMethod().GetCustomAttributes(typeof(TestCaseVersion), true).OfType<TestCaseVersion>()
                            .First();
                    return tcv.TestID;
                }
            }
        }

The problem is that when running tests through NUnit in Release mode, the method which should have the test name and these attributes is replaced by the following:

System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at NUnit.Core.Reflect.InvokeMethod(MethodInfo method, Object fixture, Object[] args)

UPDATE
For anyone who is interested, I wound up implementing the code in the following way (so that any of the attribute values could be accessed, without changing any of the existing code that uses TestCaseVersion attribute:

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface | AttributeTargets.Method, AllowMultiple = false)]
public class TestCaseVersion : PropertyAttribute
{
   public TestCaseVersion(string testCaseCode, string story, string task, string description)
   {
      base.Properties.Add("TestId", testCaseCode);
      base.Properties.Add("Description", description);
      base.Properties.Add("StoryId", story);
      base.Properties.Add("TaskId", task);
    }
}

public string GetTestID()
{
   return TestContext.CurrentContext.Test.Properties["TestId"];
}
  • 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-09T13:56:34+00:00Added an answer on June 9, 2026 at 1:56 pm

    If you are OK with having a single-valued test case version string (i.e. "001, B-8345, X543" instead of "001","B-8345","X543"), you should be able to make use of the TestContext functionality available in NUnit 2.5.7 and higher.

    Specifically, you could define and use a test context Property attribute TestCaseVersion like this:

    [Test, Property("TestCaseVersion", "001, B-8345, X543")]
    public void TestContextPropertyTest()
    {
        Console.WriteLine(TestContext.CurrentContext.Test.Properties["TestCaseVersion"]);
    }
    

    UPDATE BTW, If you do want to use a multi-valued representation of the test case version, you could define multiple properties, like this:

    [Test, Property("MajorVersion", "001"), 
     Property("MinorVersion", "B-8345"), Property("Build", "X543")]
    public void TestContextPropertyTest()
    {
        Console.WriteLine(TestContext.CurrentContext.Test.Properties["MajorVersion"]);
        Console.WriteLine(TestContext.CurrentContext.Test.Properties["MinorVersion"]);
        Console.WriteLine(TestContext.CurrentContext.Test.Properties["Build"]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a php project that needs to store information about various
I would like to store a cookie object with multiple values associated with various
I need to store various info about some movies, books, games, and maybe other
Lets say each row of our table contains information about various vehicles for sale.
Currently, we have information about our products in a variety of places. ERP, Various
Suppose you were setting up a database to store crash test data of various
I store various user details in my MySQL database. Originally it was set up
I needed to store various strings in a map but I wanted to keep
Would you consider it bad practice to store various user data in a database
I want to be able to store various Canvas items in seperate XAML files

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.