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

Non-static TestCaseSource/ValueSource #4642

Open
manfred-brands opened this issue Feb 28, 2024 · 1 comment
Open

Non-static TestCaseSource/ValueSource #4642

manfred-brands opened this issue Feb 28, 2024 · 1 comment

Comments

@manfred-brands
Copy link
Member

At the moment we require the members that are passed into the TestCaseSource and ValueSource attributes to be static.

However, if the name is null we assume the TestFixture itself is an IEnumerable and we actually instantiate the fixture to return the test parameters.

What is the reason, not to allow instance fields for the other source members?
Code wise the change wouldn't be too difficult.

object instance = member.IsStatic ? null : Reflect.Construct(sourceType, null)

Then update all further code to pass instance instead of null?

@stevenaw
Copy link
Member

@manfred-brands I found a bit of a write up about the history of this here: #3532 (comment)

That comment mentions avoiding multiple construction of objects. My (perhaps incorrect) assumption had been that it also could encourage more deterministic behavior by avoiding referencing instance data when generating test cases.

I admit, I haven't read the whole thread just yet. And, of course, decisions can always be revisited.

@jnm2 At one point you were advocating for going further towards statics in #3537. I'm unsure if that was simply for API consistency or if you had other design considerations in mind too at the time?

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

No branches or pull requests

2 participants