Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to get name/context of the running test? #416

Closed
alfeg opened this issue May 6, 2015 · 9 comments
Closed

Is it possible to get name/context of the running test? #416

alfeg opened this issue May 6, 2015 · 9 comments

Comments

@alfeg
Copy link

alfeg commented May 6, 2015

We moving from nUnit to xUnit.
In nUnit we were using TestContext to get name of running test to collect some performance stats on running tests.
Is it possible in xUnit?

@bradwilson
Copy link
Member

Sorry, there is no equivalent to TestContext in xUnit.net.

@ghost
Copy link

ghost commented May 22, 2016

Maybe it is good time to implement it? Who is the idiot thinking that xUnit is replacement for unit testing system in VS2015?

@slawomir-brzezinski-at-interxion
Copy link

slawomir-brzezinski-at-interxion commented Sep 5, 2017

Duplicated by #1359

@laurynasr
Copy link

laurynasr commented Apr 4, 2018

There actually is a way for getting some of current test information, but for some reason not exposed to general public.
You need to inject an ITestOutputHelper instance to your test class, and use some reflection magic to get an ITest instance:

public class Tests
  {
  public Tests(ITestOutputHelper output)
    {
    var type = output.GetType();
    var testMember = type.GetField("test", BindingFlags.Instance | BindingFlags.NonPublic);
    var test = (ITest)testMember.GetValue(output);
    }
<...>
  }

@bradwilson there already is a test context being used in xUnit, why can't it be injected just like ITestOutputHelper?

@otac0n
Copy link

otac0n commented Apr 16, 2018

@laurynasr This worked perfectly for my use case. +1

@danrozenberg
Copy link

I wish we could do this without needing to resort to reflection (or even without requesting an ITestOutputHelper).

@SimonCropp
Copy link
Contributor

i needed this for a few of my projects. so i bundled it into my xunit logging lib https://github.com/SimonCropp/XunitLogger#current-test

@ColinM9991
Copy link

There seem to be fundamental gaps in the Xunit framework, such as parameters via console not being supported, no TestContext equivalent.

Are these things even being considered for implementation?

@bradwilson
Copy link
Member

#621
#2001

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants