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.

Access to fixture created by AutoData attribute.

See original GitHub issue

Hi, For now i only can access the fixture like this.

[Theory, AutoData]
public void Dummy(string dummy)
{
    MethodBase method = MethodBase.GetCurrentMethod();
    IFixture fixture = method.GetCustomAttribute<AutoDataAttribute>().Fixture;


    Assert.Equal(dummy, dummy);
}

And I get the ‘AutoDataAttribute.Fixture’ is obsolete warning.

Is there a better way to access the fixture created in the AutoData attribute. I would like to mix parameter and manual creation and injection. Thanks

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
malylemire1commented, Apr 26, 2018

Yes, it’s really a better way.

Can you put this in the AutoData wiki? I have searched everywhere to find how to do this. Did not think the IOC container got the IFixture registered.

Thanks a lot!

1reaction
zvirjacommented, Apr 25, 2018

Hi,

Sure, simply ask underlying fixture to resolve IFixture instance and it will return self:

[Theory, AutoData]
public void Dummy(string dummy, IFixture fixture)
{
}

Does it work for you? 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create Mock classes in AutoDataAttribute ...
I want to inject the mock classes in the fixture, I only got one answer that helps me fix the base class warning...
Read more >
Autofixture Generate Specific Format Values By Extending ...
Extend AutoDataAttribute. To allow for our requirement to be met we need access to the Fixture instance which is being used to generate...
Read more >
Test Data Generation With AutoFixture in .NET
AutoFixture is a powerful library for test data generation in .NET projects. Its main goal is to automate the process of creating test...
Read more >
Why I stopped worrying about test setups by using ...
We're going to continue to use the XUnit's parameterized tests, and create an AutoDataAttribute to provide the parameters to the test.
Read more >
xUnit Autodata with autofixure
Autofixure => provides anonymous test data (data that is required to execute test, but the value itself is Unimportant) · Autofixure can also...
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